<!doctype html>
<html lang="en">
 <head> 
  <meta charset="UTF-8"> 
  <meta name="description" content="燎火的个人博客"> 
  <meta name="keyword" content="燎火,qq799378666,软件开发,java,c#,js,html,html5,css"> 
  <title>Spring MVC 教程,快速入门,深入分析</title> 
  <script src="/js/jquery-1.11.1.min.js"></script> 
  <script src="/js/bootstrap-3.3.5/js/bootstrap.js"></script> 
  <link href="/js/bootstrap-3.3.5/css/bootstrap.css" rel="stylesheet"> 
  <script src="/js/base.js"></script> 
  <script src="/js/nav.js"></script> 
  <script src="/js/jquery.toTop.min.js"></script> 
  <link href="/style/article.css" rel="stylesheet"> 
 </head> 
 <body> 
  <div id="main"> 
   <h3 id="title">Spring MVC 教程,快速入门,深入分析</h3> 
   <div id="content">
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">作者：赵磊</p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">博客：http://elf8848.iteye.com</p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">&nbsp;</p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);"><span style="font-size: medium;"><strong>目录&nbsp;</strong></span><br><br>一、前言<br>二、spring mvc 核心类与接口<br>三、spring mvc&nbsp;核心流程图</p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">四、spring mvc&nbsp;DispatcherServlet说明</p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">五、spring mvc 父子上下文的说明</p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">六、springMVC-mvc.xml 配置文件片段讲解&nbsp;<br>七、spring mvc&nbsp;如何访问到静态的文件，如jpg,js,css</p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">八、spring mvc&nbsp;请求如何映射到具体的Action中的方法</p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">九、&nbsp;spring mvc&nbsp;中的拦截器：<br>十、&nbsp;spring mvc&nbsp;如何使用拦截器</p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">十一、&nbsp;spring mvc&nbsp;如何实现全局的异常处理</p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">十二、&nbsp;spring mvc&nbsp;如何把全局异常记录到日志中</p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">十三、&nbsp;如何给spring3 MVC中的Action做JUnit单元测试</p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">十四、&nbsp;spring mvc&nbsp;转发与重定向 （带参数重定向）</p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">十五、&nbsp;spring mvc&nbsp;处理ajax请求</p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">十六、&nbsp;spring mvc&nbsp;关于写几个配置文件的说明&nbsp;</p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">十七、&nbsp;spring mvc&nbsp;如何取得Spring管理的bean</p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">十八、&nbsp;spring mvc&nbsp;多视图控制器</p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">十九、 &lt;mvc:annotation-driven /&gt; 到底做了什么工作&nbsp;<br>二十、 本文中springMVC.xml配置文件是核心，这里给一个下载地址</p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">&nbsp;</p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">&nbsp;</p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">&nbsp;</p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">说明：本作者是文章的原创作者，转载请注明出处：本文地址：<a href="http://elf8848.iteye.com/blog/875830" style="color: rgb(16, 138, 198);">http://elf8848.iteye.com/blog/875830</a></p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">&nbsp;</p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">&nbsp;</p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">&nbsp;</p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);"><strong><span style="font-size: medium;">一、前言：</span></strong></p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">为开发团队选择一款优秀的MVC框架是件难事儿，在众多可行的方案中决择需要很高的经验和水平。你的一个决定会影响团队未来的几年。要考虑方面太多：</p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">1、简单易用，以提高开发效率。使小部分的精力在框架上，大部分的精力放在业务上。</p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">2、性能优秀，这是一个最能吸引眼球的话题。</p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">3、尽量使用大众的框架（避免使用小众的、私有的框架），新招聘来的开发人员有一些这方面技术积累，减低人员流动再适应的影响。</p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">&nbsp;</p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">如果你还在为这件事件发愁，本文最适合你了。选择Spring MVC吧。</p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">&nbsp;</p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">Spring MVC是当前最优秀的MVC框架，自从Spring 2.5版本发布后，由于支持注解配置，易用性有了大幅度的提高。Spring 3.0更加完善，实现了对Struts 2的超越。现在越来越多的开发团队选择了Spring MVC。</p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">&nbsp;</p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">Struts2也是非常优秀的MVC构架，优点非常多比如良好的结构，拦截器的思想，丰富的功能。但这里想说的是缺点，Struts2由于采用了值栈、OGNL表达式、struts2标签库等，会导致应用的性能下降，应避免使用这些功能。而Struts2的多层拦截器、多实例action性能都很好。可以参考我写的一篇关于Spring MVC与Struts2与Servlet比较的文章<a href="http://elf8848.iteye.com/admin/blogs/698217" style="color: rgb(16, 138, 198);">《Struts2、SpringMVC、Servlet(Jsp)性能对比 测试》</a></p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">&nbsp;</p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">Spring3 MVC的优点：</p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">1、Spring3 MVC使用简单，学习成本低。学习难度小于Struts2，Struts2用不上的多余功能太多。呵呵，当然这不是决定因素。</p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">2、Spring3 MVC很容易就可以写出性能优秀的程序，Struts2要处处小心才可以写出性能优秀的程序（指MVC部分）</p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">3、Spring3 MVC的灵活是你无法想像的，Spring框架的扩展性有口皆碑，Spring3 MVC当然也不会落后，不会因使用了MVC框架而感到有任何的限制。</p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">&nbsp;</p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">Struts2的众多优点：</p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">1、老牌的知名框架，从Struts1起积累了大量用户群体。技术文档丰富。</p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">2、其它方面略...&nbsp;&nbsp; (呵呵，是不是不公平？)</p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">&nbsp;</p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">Spring的官方下载网址是：<a href="http://www.springsource.org/download" style="color: rgb(16, 138, 198);">http://www.springsource.org/download</a>&nbsp;&nbsp;&nbsp; （本文使用是的Spring 3.0.5版本）</p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">转载请注明出处：原文地址：<a href="http://elf8848.iteye.com/blog/875830" style="color: rgb(16, 138, 198);">http://elf8848.iteye.com/blog/875830</a></p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">&nbsp;</p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);"><strong><span style="font-size: medium;">二、核心类与接口：</span></strong></p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">&nbsp;</p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">先来了解一下，几个重要的接口与类。现在不知道他们是干什么的没关系，先混个脸熟，为以后认识他们打个基础。</p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">&nbsp;</p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">DispatcherServlet&nbsp;&nbsp; -- 前置控制器</p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);"><img alt="" height="205" src="http://dl.iteye.com/upload/attachment/486300/3f5703e2-b29e-3eda-a7ac-acbe4ce7a6d3.jpg" width="368"></p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">&nbsp;</p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">HandlerMapping接口 -- 处理请求的映射</p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">HandlerMapping接口的实现类：</p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">SimpleUrlHandlerMapping&nbsp; 通过配置文件，把一个URL映射到Controller</p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">DefaultAnnotationHandlerMapping&nbsp; 通过注解，把一个URL映射到Controller类上</p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);"><img alt="" height="212" src="http://dl.iteye.com/upload/attachment/486286/c6b474c8-91fa-3009-a0e9-c868ca52baf2.jpg" width="439"></p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">&nbsp;</p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">HandlerAdapter接口 -- 处理请求的映射</p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">AnnotationMethodHandlerAdapter类，通过注解，把一个URL映射到Controller类的方法上</p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);"><img alt="" height="138" src="http://dl.iteye.com/upload/attachment/486402/8475318e-d2e2-3dd2-81e9-036090f0aad1.jpg" width="411"></p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">&nbsp;</p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">Controller接口 -- 控制器</p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">由于我们使用了@Controller注解，添加了@Controller注解注解的类就可以担任控制器（Action）的职责,</p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">所以我们并没有用到这个接口。</p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);"><img alt="" height="268" src="http://dl.iteye.com/upload/attachment/486302/67b19bd0-e44c-311a-8d05-80d013cf44ae.jpg" width="367"></p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">&nbsp;</p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">&nbsp;</p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">&nbsp;</p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">HandlerInterceptor 接口--拦截器</p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">无图，我们自己实现这个接口，来完成拦截的器的工作。</p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">&nbsp;</p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">&nbsp;</p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">ViewResolver接口的实现类</p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">UrlBasedViewResolver类 通过配置文件，把一个视图名交给到一个View来处理</p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">InternalResourceViewResolver类，比上面的类，加入了JSTL的支持</p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);"><img alt="" height="293" src="http://dl.iteye.com/upload/attachment/486322/7d130bbd-577e-3b0f-94b4-8a4fb4c779d5.jpg" width="358"></p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">&nbsp;</p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">View接口</p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">JstlView类</p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);"><img alt="" height="505" src="http://dl.iteye.com/upload/attachment/486339/c1e3caff-135b-3420-90b9-d3d2033c759b.jpg" width="395"></p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">&nbsp;</p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">LocalResolver接口</p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);"><img alt="" height="150" src="http://dl.iteye.com/upload/attachment/486341/d631fde8-9c47-3902-a437-6ec6141556b5.jpg" width="284"></p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">&nbsp;</p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">HandlerExceptionResolver接口 --异常处理</p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">SimpleMappingExceptionResolver实现类</p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);"><img alt="" height="145" src="http://dl.iteye.com/upload/attachment/486343/5b6a3428-abf3-3f05-9d26-f0232fb33ec7.jpg" width="387"></p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">&nbsp;</p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">&nbsp;</p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">ModelAndView类</p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">无图。</p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">&nbsp;</p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">&nbsp;</p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">&nbsp;</p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">&nbsp;</p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">&nbsp;</p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);"><strong><span style="font-size: medium;">三、核心流程图</span></strong></p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">&nbsp;</p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">本图是我个人画的，有不严谨的地方，大家对付看吧。总比没的看强。</p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);"><img alt="" height="961" src="http://dl.iteye.com/upload/attachment/0068/8752/620f63e1-ee68-30c9-a53d-13107e634364.png" width="700" title="点击查看原始大小图片" class="magplus"></p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">转载请注明出处：本文地址：<a href="http://elf8848.iteye.com/blog/875830" style="color: rgb(16, 138, 198);">http://elf8848.iteye.com/blog/875830</a></p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">&nbsp;</p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">&nbsp;</p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);"><br><strong><span style="font-size: medium;">四、DispatcherServlet说明</span></strong></p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">&nbsp;</p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">使用Spring MVC,配置DispatcherServlet是第一步。</p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">DispatcherServlet是一个Servlet,所以可以配置多个DispatcherServlet。</p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">DispatcherServlet是前置控制器，配置在web.xml文件中的。拦截匹配的请求，Servlet拦截匹配规则要自已定义，把拦截下来的请求，依据某某规则分发到目标Controller(我们写的Action)来处理。</p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">&nbsp;</p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">“某某规则”：是根据你使用了哪个HandlerMapping接口的实现类的不同而不同。</p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">&nbsp;</p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">先来看第一个例子：</p>
    <p>Xml代码&nbsp;&nbsp;<a title="收藏这段代码" style="color: rgb(16, 138, 198); text-decoration: underline;"><img class="star" src="http://elf8848.iteye.com/images/icon_star.png" alt="收藏代码"></a></p>
    <ol class="dp-xml list-paddingleft-2" style="font-size: 1em; line-height: 1.4em; margin-bottom: 1px; padding: 2px 0px; border: 1px solid rgb(209, 215, 220); list-style-position: initial; list-style-image: initial; color: rgb(43, 145, 175);">
     <li><p><span style="color: black;"><span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&lt;</span><span class="tag-name" style="color: rgb(0, 102, 153); font-weight: bold;">web-app</span><span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&gt;</span>&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;">&nbsp;&nbsp;&nbsp;&nbsp;<span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&lt;</span><span class="tag-name" style="color: rgb(0, 102, 153); font-weight: bold;">servlet</span><span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&gt;</span>&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&lt;</span><span class="tag-name" style="color: rgb(0, 102, 153); font-weight: bold;">servlet-name</span><span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&gt;</span>example<span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&lt;/</span><span class="tag-name" style="color: rgb(0, 102, 153); font-weight: bold;">servlet-name</span><span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&gt;</span>&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&lt;</span><span class="tag-name" style="color: rgb(0, 102, 153); font-weight: bold;">servlet-class</span><span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&gt;</span>org.springframework.web.servlet.DispatcherServlet<span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&lt;/</span><span class="tag-name" style="color: rgb(0, 102, 153); font-weight: bold;">servlet-class</span><span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&gt;</span>&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&lt;</span><span class="tag-name" style="color: rgb(0, 102, 153); font-weight: bold;">load-on-startup</span><span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&gt;</span>1<span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&lt;/</span><span class="tag-name" style="color: rgb(0, 102, 153); font-weight: bold;">load-on-startup</span><span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&gt;</span>&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;">&nbsp;&nbsp;&nbsp;&nbsp;<span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&lt;/</span><span class="tag-name" style="color: rgb(0, 102, 153); font-weight: bold;">servlet</span><span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&gt;</span>&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;">&nbsp;&nbsp;&nbsp;&nbsp;<span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&lt;</span><span class="tag-name" style="color: rgb(0, 102, 153); font-weight: bold;">servlet-mapping</span><span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&gt;</span>&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&lt;</span><span class="tag-name" style="color: rgb(0, 102, 153); font-weight: bold;">servlet-name</span><span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&gt;</span>example<span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&lt;/</span><span class="tag-name" style="color: rgb(0, 102, 153); font-weight: bold;">servlet-name</span><span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&gt;</span>&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&lt;</span><span class="tag-name" style="color: rgb(0, 102, 153); font-weight: bold;">url-pattern</span><span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&gt;</span>*.form<span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&lt;/</span><span class="tag-name" style="color: rgb(0, 102, 153); font-weight: bold;">url-pattern</span><span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&gt;</span>&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;">&nbsp;&nbsp;&nbsp;&nbsp;<span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&lt;/</span><span class="tag-name" style="color: rgb(0, 102, 153); font-weight: bold;">servlet-mapping</span><span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&gt;</span>&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;"><span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&lt;/</span><span class="tag-name" style="color: rgb(0, 102, 153); font-weight: bold;">web-app</span><span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&gt;</span>&nbsp;&nbsp;</span></p></li>
    </ol>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">&nbsp;&lt;load-on-startup&gt;1&lt;/load-on-startup&gt;是启动顺序，让这个Servlet随Servletp容器一起启动。</p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">&nbsp;&lt;url-pattern&gt;*.form&lt;/url-pattern&gt; 会拦截*.form结尾的请求。</p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">&nbsp;</p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">&nbsp;&lt;servlet-name&gt;example&lt;/servlet-name&gt;这个Servlet的名字是example，可以有多个DispatcherServlet，是通过名字来区分的。每一个DispatcherServlet有自己的WebApplicationContext上下文对象。同时保存的ServletContext中和Request对象中，关于key，以后说明。</p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">&nbsp;</p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">在DispatcherServlet的初始化过程中，框架会在web应用的 WEB-INF文件夹下寻找名为[servlet-name]-servlet.xml 的配置文件，生成文件中定义的bean。</p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">&nbsp;</p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">&nbsp;</p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">第二个例子：</p>
    <p>Xml代码&nbsp;&nbsp;<a title="收藏这段代码" style="color: rgb(16, 138, 198); text-decoration: underline;"><img class="star" src="http://elf8848.iteye.com/images/icon_star.png" alt="收藏代码"></a></p>
    <ol class="dp-xml list-paddingleft-2" style="font-size: 1em; line-height: 1.4em; margin-bottom: 1px; padding: 2px 0px; border: 1px solid rgb(209, 215, 220); list-style-position: initial; list-style-image: initial; color: rgb(43, 145, 175);">
     <li><p><span style="color: black;"><span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&lt;</span><span class="tag-name" style="color: rgb(0, 102, 153); font-weight: bold;">servlet</span><span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&gt;</span>&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;">&nbsp;&nbsp;&nbsp;&nbsp;<span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&lt;</span><span class="tag-name" style="color: rgb(0, 102, 153); font-weight: bold;">servlet-name</span><span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&gt;</span>springMVC<span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&lt;/</span><span class="tag-name" style="color: rgb(0, 102, 153); font-weight: bold;">servlet-name</span><span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&gt;</span>&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;">&nbsp;&nbsp;&nbsp;&nbsp;<span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&lt;</span><span class="tag-name" style="color: rgb(0, 102, 153); font-weight: bold;">servlet-class</span><span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&gt;</span>org.springframework.web.servlet.DispatcherServlet<span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&lt;/</span><span class="tag-name" style="color: rgb(0, 102, 153); font-weight: bold;">servlet-class</span><span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&gt;</span>&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;">&nbsp;&nbsp;&nbsp;&nbsp;<span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&lt;</span><span class="tag-name" style="color: rgb(0, 102, 153); font-weight: bold;">init-param</span><span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&gt;</span>&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&lt;</span><span class="tag-name" style="color: rgb(0, 102, 153); font-weight: bold;">param-name</span><span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&gt;</span>contextConfigLocation<span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&lt;/</span><span class="tag-name" style="color: rgb(0, 102, 153); font-weight: bold;">param-name</span><span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&gt;</span>&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&lt;</span><span class="tag-name" style="color: rgb(0, 102, 153); font-weight: bold;">param-value</span><span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&gt;</span>classpath*:/springMVC.xml<span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&lt;/</span><span class="tag-name" style="color: rgb(0, 102, 153); font-weight: bold;">param-value</span><span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&gt;</span>&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;">&nbsp;&nbsp;&nbsp;&nbsp;<span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&lt;/</span><span class="tag-name" style="color: rgb(0, 102, 153); font-weight: bold;">init-param</span><span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&gt;</span>&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;">&nbsp;&nbsp;&nbsp;&nbsp;<span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&lt;</span><span class="tag-name" style="color: rgb(0, 102, 153); font-weight: bold;">load-on-startup</span><span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&gt;</span>1<span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&lt;/</span><span class="tag-name" style="color: rgb(0, 102, 153); font-weight: bold;">load-on-startup</span><span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&gt;</span>&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;"><span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&lt;/</span><span class="tag-name" style="color: rgb(0, 102, 153); font-weight: bold;">servlet</span><span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&gt;</span>&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;"><span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&lt;</span><span class="tag-name" style="color: rgb(0, 102, 153); font-weight: bold;">servlet-mapping</span><span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&gt;</span>&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;">&nbsp;&nbsp;&nbsp;&nbsp;<span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&lt;</span><span class="tag-name" style="color: rgb(0, 102, 153); font-weight: bold;">servlet-name</span><span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&gt;</span>springMVC<span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&lt;/</span><span class="tag-name" style="color: rgb(0, 102, 153); font-weight: bold;">servlet-name</span><span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&gt;</span>&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;">&nbsp;&nbsp;&nbsp;&nbsp;<span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&lt;</span><span class="tag-name" style="color: rgb(0, 102, 153); font-weight: bold;">url-pattern</span><span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&gt;</span>/<span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&lt;/</span><span class="tag-name" style="color: rgb(0, 102, 153); font-weight: bold;">url-pattern</span><span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&gt;</span>&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;"><span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&lt;/</span><span class="tag-name" style="color: rgb(0, 102, 153); font-weight: bold;">servlet-mapping</span><span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&gt;</span>&nbsp;&nbsp;</span></p></li>
    </ol>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">指明了配置文件的文件名，不使用默认配置文件名，而使用springMVC.xml配置文件。</p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">其中&lt;param-value&gt;**.xml&lt;/param-value&gt; 这里可以使用多种写法<br>1、不写,使用默认值:/WEB-INF/&lt;servlet-name&gt;-servlet.xml<br>2、&lt;param-value&gt;/WEB-INF/classes/springMVC.xml&lt;/param-value&gt;<br>3、&lt;param-value&gt;classpath*:springMVC-mvc.xml&lt;/param-value&gt;<br>4、多个值用逗号分隔</p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">&nbsp;</p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);"><br><strong>Servlet拦截匹配规则可以自已定义，拦截哪种URL合适？</strong>&nbsp;<br>当映射为@RequestMapping("/user/add")时，为例：</p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);"><br>1、拦截*.do、*.htm， 例如：/user/add.do</p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">这是最传统的方式，最简单也最实用。不会导致静态文件（jpg,js,css）被拦截。</p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">&nbsp;</p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">2、拦截/，例如：/user/add</p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">可以实现现在很流行的REST风格。很多互联网类型的应用很喜欢这种风格的URL。</p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">弊端：会导致静态文件（jpg,js,css）被拦截后不能正常显示。想实现REST风格，事情就是麻烦一些。后面有解决办法还算简单。</p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">&nbsp;</p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">3、拦截/*，这是一个错误的方式，请求可以走到Action中，但转到jsp时再次被拦截，不能访问到jsp。</p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">&nbsp;</p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">转载请注明出处：本文地址：<a href="http://elf8848.iteye.com/blog/875830" style="color: rgb(16, 138, 198);">http://elf8848.iteye.com/blog/875830</a></p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">&nbsp;</p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);"><span style="font-size: medium;"><strong>五、父子上下文(WebApplicationContext)</strong></span></p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">&nbsp;</p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">如果你使用了listener监听器来加载配置，一般在Struts+Spring+Hibernate的项目中都是使用listener监听器的。如下</p>
    <p>Java代码&nbsp;&nbsp;<a title="收藏这段代码" style="color: rgb(16, 138, 198); text-decoration: underline;"><img class="star" src="http://elf8848.iteye.com/images/icon_star.png" alt="收藏代码"></a></p>
    <ol class="dp-j list-paddingleft-2" style="font-size: 1em; line-height: 1.4em; margin-bottom: 1px; padding: 2px 0px; border: 1px solid rgb(209, 215, 220); list-style-position: initial; list-style-image: initial; color: rgb(43, 145, 175);">
     <li><p><span style="color: black;">&lt;listener&gt;&nbsp;&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;">&nbsp;&nbsp;&lt;listener-<span class="keyword" style="color: rgb(127, 0, 85); font-weight: bold;">class</span>&gt;org.springframework.web.context.ContextLoaderListener&lt;/listener-<span class="keyword" style="color: rgb(127, 0, 85); font-weight: bold;">class</span>&gt;&nbsp;&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;">&lt;/listener&gt;&nbsp;&nbsp;&nbsp;</span></p></li>
    </ol>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">&nbsp;</p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">&nbsp;</p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">Spring会创建一个WebApplicationContext上下文，称为父上下文（父容器） ，保存在 ServletContext中，key是WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE的值。</p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">可以使用Spring提供的工具类取出上下文对象：WebApplicationContextUtils.getWebApplicationContext(ServletContext);</p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">&nbsp;</p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">DispatcherServlet是一个Servlet,可以同时配置多个，每个 DispatcherServlet有一个自己的上下文对象（WebApplicationContext），称为子上下文（子容器），子上下文可以访问父上下文中的内容，但父上下文不能访问子上下文中的内容。 它也保存在 ServletContext中，key是"org.springframework.web.servlet.FrameworkServlet.CONTEXT"+Servlet名称。当一个Request对象产生时，会把这个子上下文对象（WebApplicationContext）保存在Request对象中，key是DispatcherServlet.class.getName() + ".CONTEXT"。</p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">可以使用工具类取出上下文对象：RequestContextUtils.getWebApplicationContext(request);</p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">&nbsp;</p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">&nbsp;</p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">说明 ：Spring 并没有限制我们，必须使用父子上下文。我们可以自己决定如何使用。</p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">&nbsp;</p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);"><strong>方案一，传统型：</strong></p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">父上下文容器中保存数据源、服务层、DAO层、事务的Bean。</p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">子上下文容器中保存Mvc相关的Action的Bean.</p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">事务控制在服务层。</p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">由于父上下文容器不能访问子上下文容器中内容，事务的Bean在父上下文容器中，无法访问子上下文容器中内容，就无法对子上下文容器中Action进行AOP（事务）。</p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">当然，做为“传统型”方案，也没有必要这要做。</p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">&nbsp;</p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);"><strong>方案二，激进型：</strong></p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">Java世界的“面向接口编程”的思想是正确的，但在增删改查为主业务的系统里，Dao层接口，Dao层实现类，Service层接口，Service层实现类，Action父类，Action。再加上众多的O(vo\po\bo)和jsp页面。写一个小功能 7、8个类就写出来了。 开发者说我就是想接点私活儿，和PHP，ASP抢抢饭碗，但我又是Java程序员。最好的结果是大项目能做好，小项目能做快。所以“激进型”方案就出现了-----没有接口、没有Service层、还可以没有众多的O(vo\po\bo)。那没有Service层事务控制在哪一层？只好上升的Action层。</p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">本文不想说这是不是正确的思想，我想说的是Spring不会限制你这样做。</p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">由于有了父子上下文，你将无法实现这一目标。解决方案是<span style="color: rgb(255, 0, 0);"><strong>只使用子上下文容器，不要父上下文容器</strong>&nbsp;</span>。所以数据源、服务层、DAO层、事务的Bean、Action的Bean都放在子上下文容器中。就可以实现了，事务（注解事务）就正常工作了。这样才够激进。</p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">总结：不使用listener监听器来加载spring的配置文件，只使用DispatcherServlet来加载spring的配置，不要父子上下文，只使用一个DispatcherServlet，事情就简单了，什么麻烦事儿也没有了。</p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">&nbsp;</p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">&nbsp;</p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">&nbsp;</p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">Java--大项目能做好--按传统方式做，规规矩矩的做，好扩展，好维护。</p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">Java--小项目能做快--按激进方式做，一周时间就可以出一个版本，先上线接受市场(用户)的反馈，再改进，再反馈，时间就是生命(成本)。</p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">&nbsp;</p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">转载请注明出处：原文地址：<a href="http://elf8848.iteye.com/blog/875830" style="color: rgb(16, 138, 198);">http://elf8848.iteye.com/blog/875830</a></p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">&nbsp;</p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);"><span style="font-size: medium;"><strong>六、springMVC-mvc.xml 配置文件片段讲解</strong>&nbsp;<span style="font-size: small;">（未使用默认配置文件名）</span></span></p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">&nbsp;</p>
    <p>Xml代码&nbsp;&nbsp;<a title="收藏这段代码" style="color: rgb(16, 138, 198); text-decoration: underline;"><img class="star" src="http://elf8848.iteye.com/images/icon_star.png" alt="收藏代码"></a></p>
    <ol class="dp-xml list-paddingleft-2" style="font-size: 1em; line-height: 1.4em; margin-bottom: 1px; padding: 2px 0px; border: 1px solid rgb(209, 215, 220); list-style-position: initial; list-style-image: initial; color: rgb(43, 145, 175);">
     <li><p><span style="color: black;"><span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&lt;?</span><span class="tag-name" style="color: rgb(0, 102, 153); font-weight: bold;">xml</span>&nbsp;<span class="attribute" style="color: red;">version</span>=<span class="attribute-value" style="color: blue;">"1.0"</span>&nbsp;<span class="attribute" style="color: red;">encoding</span>=<span class="attribute-value" style="color: blue;">"UTF-8"</span><span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">?&gt;</span>&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;"><span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&lt;</span><span class="tag-name" style="color: rgb(0, 102, 153); font-weight: bold;">beans</span>&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;">&nbsp;&nbsp;&nbsp;&nbsp;<span class="attribute" style="color: red;">xmlns</span>=<span class="attribute-value" style="color: blue;">"http://www.springframework.org/schema/beans"</span>&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;">&nbsp;&nbsp;&nbsp;&nbsp;<span class="attribute" style="color: red;">xmlns:xsi</span>=<span class="attribute-value" style="color: blue;">"http://www.w3.org/2001/XMLSchema-instance"</span>&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;">&nbsp;&nbsp;&nbsp;&nbsp;<span class="attribute" style="color: red;">xmlns:tx</span>=<span class="attribute-value" style="color: blue;">"http://www.springframework.org/schema/tx"</span>&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;">&nbsp;&nbsp;&nbsp;&nbsp;<span class="attribute" style="color: red;">xmlns:context</span>=<span class="attribute-value" style="color: blue;">"http://www.springframework.org/schema/context"</span>&nbsp;&nbsp;&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;">&nbsp;&nbsp;&nbsp;&nbsp;<span class="attribute" style="color: red;">xmlns:mvc</span>=<span class="attribute-value" style="color: blue;">"http://www.springframework.org/schema/mvc"</span>&nbsp;&nbsp;&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;">&nbsp;&nbsp;&nbsp;&nbsp;<span class="attribute" style="color: red;">xsi:schemaLocation</span>="http://www.springframework.org/schema/beans&nbsp;&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;">&nbsp;&nbsp;&nbsp;&nbsp;http://www.springframework.org/schema/beans/spring-beans-3.0.xsd&nbsp;&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;">&nbsp;&nbsp;&nbsp;&nbsp;http://www.springframework.org/schema/tx&nbsp;&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;">&nbsp;&nbsp;&nbsp;&nbsp;http://www.springframework.org/schema/tx/spring-tx-3.0.xsd&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;">&nbsp;&nbsp;&nbsp;&nbsp;http://www.springframework.org/schema/context&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;">&nbsp;&nbsp;&nbsp;&nbsp;http://www.springframework.org/schema/context/spring-context-3.0.xsd&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;">&nbsp;&nbsp;&nbsp;&nbsp;http://www.springframework.org/schema/mvc&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;">&nbsp;&nbsp;&nbsp;&nbsp;http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd"<span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&gt;</span>&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;">&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;">&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;">&nbsp;&nbsp;&nbsp;&nbsp;<span class="comments" style="color: rgb(0, 130, 0); padding: 0px; margin: 0px; width: auto; border: 0px;">&lt;!--&nbsp;自动扫描的包名&nbsp;--&gt;</span>&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;">&nbsp;&nbsp;&nbsp;&nbsp;<span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&lt;</span><span class="tag-name" style="color: rgb(0, 102, 153); font-weight: bold;">context:component-scan</span>&nbsp;<span class="attribute" style="color: red;">base-package</span>=<span class="attribute-value" style="color: blue;">"com.app,com.core,JUnit4"</span>&nbsp;<span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&gt;</span><span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&lt;/</span><span class="tag-name" style="color: rgb(0, 102, 153); font-weight: bold;">context:component-scan</span><span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&gt;</span>&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;">&nbsp;&nbsp;&nbsp;&nbsp;<span class="comments" style="color: rgb(0, 130, 0); padding: 0px; margin: 0px; width: auto; border: 0px;">&lt;!--&nbsp;默认的注解映射的支持&nbsp;--&gt;</span>&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;">&nbsp;&nbsp;&nbsp;&nbsp;<span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&lt;</span><span class="tag-name" style="color: rgb(0, 102, 153); font-weight: bold;">mvc:annotation-driven</span>&nbsp;<span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">/&gt;</span>&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;">&nbsp;&nbsp;&nbsp;&nbsp;<span class="comments" style="color: rgb(0, 130, 0); padding: 0px; margin: 0px; width: auto; border: 0px;">&lt;!--&nbsp;视图解释类&nbsp;--&gt;</span>&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;">&nbsp;&nbsp;&nbsp;&nbsp;<span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&lt;</span><span class="tag-name" style="color: rgb(0, 102, 153); font-weight: bold;">bean</span>&nbsp;<span class="attribute" style="color: red;">class</span>=<span class="attribute-value" style="color: blue;">"org.springframework.web.servlet.view.InternalResourceViewResolver"</span><span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&gt;</span>&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&lt;</span><span class="tag-name" style="color: rgb(0, 102, 153); font-weight: bold;">property</span>&nbsp;<span class="attribute" style="color: red;">name</span>=<span class="attribute-value" style="color: blue;">"prefix"</span>&nbsp;<span class="attribute" style="color: red;">value</span>=<span class="attribute-value" style="color: blue;">"/WEB-INF/jsp/"</span><span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">/&gt;</span>&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&lt;</span><span class="tag-name" style="color: rgb(0, 102, 153); font-weight: bold;">property</span>&nbsp;<span class="attribute" style="color: red;">name</span>=<span class="attribute-value" style="color: blue;">"suffix"</span>&nbsp;<span class="attribute" style="color: red;">value</span>=<span class="attribute-value" style="color: blue;">".jsp"</span><span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">/&gt;</span><span class="comments" style="color: rgb(0, 130, 0); padding: 0px; margin: 0px; width: auto; border: 0px;">&lt;!--可为空,方便实现自已的依据扩展名来选择视图解释类的逻辑&nbsp;&nbsp;--&gt;</span>&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&lt;</span><span class="tag-name" style="color: rgb(0, 102, 153); font-weight: bold;">property</span>&nbsp;<span class="attribute" style="color: red;">name</span>=<span class="attribute-value" style="color: blue;">"viewClass"</span>&nbsp;<span class="attribute" style="color: red;">value</span>=<span class="attribute-value" style="color: blue;">"org.springframework.web.servlet.view.JstlView"</span>&nbsp;<span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">/&gt;</span>&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;">&nbsp;&nbsp;&nbsp;&nbsp;<span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&lt;/</span><span class="tag-name" style="color: rgb(0, 102, 153); font-weight: bold;">bean</span><span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&gt;</span>&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;">&nbsp;&nbsp;&nbsp;&nbsp;<span class="comments" style="color: rgb(0, 130, 0); padding: 0px; margin: 0px; width: auto; border: 0px;">&lt;!--&nbsp;拦截器&nbsp;--&gt;</span>&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;">&nbsp;&nbsp;&nbsp;&nbsp;<span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&lt;</span><span class="tag-name" style="color: rgb(0, 102, 153); font-weight: bold;">mvc:interceptors</span><span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&gt;</span>&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&lt;</span><span class="tag-name" style="color: rgb(0, 102, 153); font-weight: bold;">bean</span>&nbsp;<span class="attribute" style="color: red;">class</span>=<span class="attribute-value" style="color: blue;">"com.core.mvc.MyInteceptor"</span>&nbsp;<span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">/&gt;</span>&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;">&nbsp;&nbsp;&nbsp;&nbsp;<span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&lt;/</span><span class="tag-name" style="color: rgb(0, 102, 153); font-weight: bold;">mvc:interceptors</span><span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&gt;</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;">&nbsp;&nbsp;&nbsp;&nbsp;<span class="comments" style="color: rgb(0, 130, 0); padding: 0px; margin: 0px; width: auto; border: 0px;">&lt;!--&nbsp;对静态资源文件的访问&nbsp;&nbsp;方案一&nbsp;（二选一）&nbsp;--&gt;</span>&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;">&nbsp;&nbsp;&nbsp;&nbsp;<span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&lt;</span><span class="tag-name" style="color: rgb(0, 102, 153); font-weight: bold;">mvc:default-servlet-handler</span><span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">/&gt;</span>&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;">&nbsp;&nbsp;&nbsp;&nbsp;<span class="comments" style="color: rgb(0, 130, 0); padding: 0px; margin: 0px; width: auto; border: 0px;">&lt;!--&nbsp;对静态资源文件的访问&nbsp;&nbsp;方案二&nbsp;（二选一）--&gt;</span>&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;">&nbsp;&nbsp;&nbsp;&nbsp;<span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&lt;</span><span class="tag-name" style="color: rgb(0, 102, 153); font-weight: bold;">mvc:resources</span>&nbsp;<span class="attribute" style="color: red;">mapping</span>=<span class="attribute-value" style="color: blue;">"/images/**"</span>&nbsp;<span class="attribute" style="color: red;">location</span>=<span class="attribute-value" style="color: blue;">"/images/"</span>&nbsp;<span class="attribute" style="color: red;">cache-period</span>=<span class="attribute-value" style="color: blue;">"31556926"</span><span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">/&gt;</span>&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;">&nbsp;&nbsp;&nbsp;&nbsp;<span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&lt;</span><span class="tag-name" style="color: rgb(0, 102, 153); font-weight: bold;">mvc:resources</span>&nbsp;<span class="attribute" style="color: red;">mapping</span>=<span class="attribute-value" style="color: blue;">"/js/**"</span>&nbsp;<span class="attribute" style="color: red;">location</span>=<span class="attribute-value" style="color: blue;">"/js/"</span>&nbsp;<span class="attribute" style="color: red;">cache-period</span>=<span class="attribute-value" style="color: blue;">"31556926"</span><span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">/&gt;</span>&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;">&nbsp;&nbsp;&nbsp;&nbsp;<span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&lt;</span><span class="tag-name" style="color: rgb(0, 102, 153); font-weight: bold;">mvc:resources</span>&nbsp;<span class="attribute" style="color: red;">mapping</span>=<span class="attribute-value" style="color: blue;">"/css/**"</span>&nbsp;<span class="attribute" style="color: red;">location</span>=<span class="attribute-value" style="color: blue;">"/css/"</span>&nbsp;<span class="attribute" style="color: red;">cache-period</span>=<span class="attribute-value" style="color: blue;">"31556926"</span><span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">/&gt;</span>&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;">&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;"><span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&lt;/</span><span class="tag-name" style="color: rgb(0, 102, 153); font-weight: bold;">beans</span><span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&gt;</span>&nbsp;&nbsp;&nbsp;</span></p></li>
    </ol>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">&nbsp;</p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">&lt;context:component-scan/&gt; 扫描指定的包中的类上的注解，常用的注解有：</p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">@Controller 声明Action组件<br>@Service&nbsp;&nbsp;&nbsp; 声明Service组件&nbsp;&nbsp;&nbsp; @Service("myMovieLister")&nbsp;<br>@Repository 声明Dao组件<br>@Component&nbsp;&nbsp; 泛指组件, 当不好归类时.&nbsp;<br>@RequestMapping("/menu")&nbsp; 请求映射<br>@Resource&nbsp; 用于注入，( j2ee提供的 ) 默认按名称装配，@Resource(name="beanName")&nbsp;<br>@Autowired 用于注入，(srping提供的) 默认按类型装配&nbsp;<br>@Transactional( rollbackFor={Exception.class}) 事务管理<br>@ResponseBody<br>@Scope("prototype")&nbsp;&nbsp; 设定bean的作用域</p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">&nbsp;</p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">&lt;mvc:annotation-driven /&gt; 是一种简写形式，完全可以手动配置替代这种简写形式，简写形式可以让初学都快速应用默认配置方案。&lt;mvc:annotation-driven /&gt; 会自动注册DefaultAnnotationHandlerMapping与AnnotationMethodHandlerAdapter 两个bean,是spring MVC为@Controllers分发请求所必须的。<br>并提供了：数据绑定支持，@NumberFormatannotation支持，@DateTimeFormat支持，@Valid支持，读写XML的支持（JAXB），读写JSON的支持（Jackson）。<br>后面，我们处理响应ajax请求时，就使用到了对json的支持。<br>后面，对action写JUnit单元测试时，要从spring IOC容器中取DefaultAnnotationHandlerMapping与AnnotationMethodHandlerAdapter 两个bean，来完成测试，取的时候要知道是&lt;mvc:annotation-driven /&gt;这一句注册的这两个bean。</p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);"><span style="font-size: small;">如何替换</span>&nbsp;<span style="font-size: small;">&lt;mvc:annotation-driven /&gt;？他到底做了什么工作，请看，最后面的 十九节&nbsp;</span><span style="font-size: small;">&lt;mvc:annotation-driven /&gt;&nbsp;</span><span style="font-size: small;">到底做了什么工作。</span></p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">&nbsp;</p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">&lt;mvc:interceptors/&gt; 是一种简写形式。通过看前面的大图，知道，我们可以配置多个HandlerMapping。&lt;mvc:interceptors/&gt;会为每一个HandlerMapping，注入一个拦截器。其实我们也可以手动配置为每个HandlerMapping注入一个拦截器。</p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">&nbsp;</p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">&lt;mvc:default-servlet-handler/&gt; 使用默认的Servlet来响应静态文件。</p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">&nbsp;</p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">&lt;mvc:resources mapping="/images/**" location="/images/" cache-period="31556926"/&gt; 匹配URL&nbsp; /images/**&nbsp; 的URL被当做静态资源，由Spring读出到内存中再响应http。</p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">转载请注明出处：本文地址：<a href="http://elf8848.iteye.com/blog/875830" style="color: rgb(16, 138, 198);">http://elf8848.iteye.com/blog/875830</a></p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);"><span style="font-size: small;">&nbsp;<br><strong><span style="font-size: medium;">七、如何访问到静态的文件，如jpg,js,css？</span></strong></span></p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">&nbsp;</p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">&nbsp;</p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);"><span style="font-size: small;">如何你的DispatcherServlet拦截"*.do"这样的有后缀的URL，就不存在访问不到静态资源的问题。<br><br>如果你的DispatcherServlet拦截"/"，为了实现REST风格，拦截了所有的请求，那么同时对*.js,*.jpg等静态文件的访问也就被拦截了。<br><br>我们要解决这个问题。</span></p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">&nbsp;</p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);"><span style="font-size: small;">目的：可以正常访问静态文件，不可以找不到静态文件报404。</span></p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);"><span style="font-size: small;">&nbsp;<br>方案一：激活Tomcat的defaultServlet来处理静态文件<br></span></p>
    <p>Xml代码&nbsp;&nbsp;<a title="收藏这段代码" style="color: rgb(16, 138, 198); text-decoration: underline;"><img class="star" src="http://elf8848.iteye.com/images/icon_star.png" alt="收藏代码"></a></p>
    <ol class="dp-xml list-paddingleft-2" style="font-size: 1em; line-height: 1.4em; margin-bottom: 1px; padding: 2px 0px; border: 1px solid rgb(209, 215, 220); list-style-position: initial; list-style-image: initial; color: rgb(43, 145, 175);">
     <li><p><span style="color: black;"><span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&lt;</span><span class="tag-name" style="color: rgb(0, 102, 153); font-weight: bold;">servlet-mapping</span><span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&gt;</span>&nbsp;&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;">&nbsp;&nbsp;&nbsp;&nbsp;<span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&lt;</span><span class="tag-name" style="color: rgb(0, 102, 153); font-weight: bold;">servlet-name</span><span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&gt;</span>default<span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&lt;/</span><span class="tag-name" style="color: rgb(0, 102, 153); font-weight: bold;">servlet-name</span><span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&gt;</span>&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;">&nbsp;&nbsp;&nbsp;&nbsp;<span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&lt;</span><span class="tag-name" style="color: rgb(0, 102, 153); font-weight: bold;">url-pattern</span><span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&gt;</span>*.jpg<span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&lt;/</span><span class="tag-name" style="color: rgb(0, 102, 153); font-weight: bold;">url-pattern</span><span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&gt;</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;"><span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&lt;/</span><span class="tag-name" style="color: rgb(0, 102, 153); font-weight: bold;">servlet-mapping</span><span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&gt;</span>&nbsp;&nbsp;&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;"><span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&lt;</span><span class="tag-name" style="color: rgb(0, 102, 153); font-weight: bold;">servlet-mapping</span><span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&gt;</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;">&nbsp;&nbsp;&nbsp;&nbsp;<span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&lt;</span><span class="tag-name" style="color: rgb(0, 102, 153); font-weight: bold;">servlet-name</span><span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&gt;</span>default<span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&lt;/</span><span class="tag-name" style="color: rgb(0, 102, 153); font-weight: bold;">servlet-name</span><span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&gt;</span>&nbsp;&nbsp;&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;">&nbsp;&nbsp;&nbsp;&nbsp;<span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&lt;</span><span class="tag-name" style="color: rgb(0, 102, 153); font-weight: bold;">url-pattern</span><span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&gt;</span>*.js<span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&lt;/</span><span class="tag-name" style="color: rgb(0, 102, 153); font-weight: bold;">url-pattern</span><span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&gt;</span>&nbsp;&nbsp;&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;"><span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&lt;/</span><span class="tag-name" style="color: rgb(0, 102, 153); font-weight: bold;">servlet-mapping</span><span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&gt;</span>&nbsp;&nbsp;&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;"><span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&lt;</span><span class="tag-name" style="color: rgb(0, 102, 153); font-weight: bold;">servlet-mapping</span><span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&gt;</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;">&nbsp;&nbsp;&nbsp;&nbsp;<span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&lt;</span><span class="tag-name" style="color: rgb(0, 102, 153); font-weight: bold;">servlet-name</span><span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&gt;</span>default<span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&lt;/</span><span class="tag-name" style="color: rgb(0, 102, 153); font-weight: bold;">servlet-name</span><span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&gt;</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;">&nbsp;&nbsp;&nbsp;&nbsp;<span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&lt;</span><span class="tag-name" style="color: rgb(0, 102, 153); font-weight: bold;">url-pattern</span><span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&gt;</span>*.css<span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&lt;/</span><span class="tag-name" style="color: rgb(0, 102, 153); font-weight: bold;">url-pattern</span><span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&gt;</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;"><span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&lt;/</span><span class="tag-name" style="color: rgb(0, 102, 153); font-weight: bold;">servlet-mapping</span><span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&gt;</span>&nbsp;&nbsp;&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;">要配置多个，每种文件配置一个&nbsp;&nbsp;&nbsp;</span></p></li>
    </ol>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);"><span style="font-size: small;">要写在DispatcherServlet的前面， 让</span>&nbsp;<span style="font-size: small;">defaultServlet先拦截请求，这样请求就不会进入Spring了，我想性能是最好的吧。</span></p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);"><span style="font-size: small;"><br></span></p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);"><span style="color: rgb(255, 0, 0);"><span style="font-size: small;">Tomcat, Jetty, JBoss, and GlassFish 自带的默认Servlet的名字 -- "default"<br>Google App Engine&nbsp;</span><span style="font-size: small;">自带的</span>&nbsp;<span style="font-size: small;">默认Servlet的名字 -- "_ah_default"<br>Resin&nbsp;</span><span style="font-size: small;">自带的</span>&nbsp;<span style="font-size: small;">默认Servlet的名字 -- "resin-file"<br>WebLogic</span>&nbsp;<span style="font-size: small;">自带的</span>&nbsp;<span style="font-size: small;">默认Servlet的名字&nbsp; -- "FileServlet"<br>WebSphere&nbsp;&nbsp;</span><span style="font-size: small;">自带的</span>&nbsp;<span style="font-size: small;">默认Servlet的名字 -- "SimpleFileServlet"&nbsp;</span></span></p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">&nbsp;</p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">&nbsp;</p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);"><br><span style="font-size: small;">方案二： 在spring3.0.4以后版本提供了mvc:resources ， &nbsp;使用方法：<br></span></p>
    <p>Xml代码&nbsp;&nbsp;<a title="收藏这段代码" style="color: rgb(16, 138, 198); text-decoration: underline;"><img class="star" src="http://elf8848.iteye.com/images/icon_star.png" alt="收藏代码"></a></p>
    <ol class="dp-xml list-paddingleft-2" style="font-size: 1em; line-height: 1.4em; margin-bottom: 1px; padding: 2px 0px; border: 1px solid rgb(209, 215, 220); list-style-position: initial; list-style-image: initial; color: rgb(43, 145, 175);">
     <li><p><span style="color: black;"><span class="comments" style="color: rgb(0, 130, 0); padding: 0px; margin: 0px; width: auto; border: 0px;">&lt;!--&nbsp;对静态资源文件的访问&nbsp;--&gt;</span>&nbsp;&nbsp;&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;"><span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&lt;</span><span class="tag-name" style="color: rgb(0, 102, 153); font-weight: bold;">mvc:resources</span>&nbsp;<span class="attribute" style="color: red;">mapping</span>=<span class="attribute-value" style="color: blue;">"/images/**"</span>&nbsp;<span class="attribute" style="color: red;">location</span>=<span class="attribute-value" style="color: blue;">"/images/"</span>&nbsp;<span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">/&gt;</span>&nbsp;&nbsp;</span></p></li>
    </ol>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">&nbsp;&nbsp;<br><span style="font-size: small;">/images/**映射到ResourceHttpRequestHandler进行处理，location指定静态资源的位置.可以是web application根目录下、jar包里面，这样可以把静态资源压缩到jar包中。cache-period 可以使得静态资源进行web cache&nbsp;<br>&nbsp;<br>如果出现下面的错误，可能是没有配置&lt;mvc:annotation-driven /&gt;的原因。&nbsp;<br>报错WARNING: No mapping found for HTTP request with URI [/mvc/user/findUser/lisi/770] in DispatcherServlet with name 'springMVC'<br></span></p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);"><span style="font-size: small;">&nbsp;</span></p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);"><span style="font-size: small;">使用&lt;mvc:resources/&gt;元素,把mapping的URI注册到SimpleUrlHandlerMapping的urlMap中,<br>key为mapping的URI pattern值,而value为ResourceHttpRequestHandler,<br>这样就巧妙的把对静态资源的访问由HandlerMapping转到ResourceHttpRequestHandler处理并返回,所以就支持classpath目录,jar包内静态资源的访问.<br>另外需要注意的一点是,不要对SimpleUrlHandlerMapping设置defaultHandler.因为对static uri的defaultHandler就是ResourceHttpRequestHandler,<br>否则无法处理static resources request.</span></p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">&nbsp;</p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">&nbsp;</p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">方案三 ，使用&lt;mvc:default-servlet-handler/&gt;</p>
    <p>Xml代码&nbsp;&nbsp;<a title="收藏这段代码" style="color: rgb(16, 138, 198); text-decoration: underline;"><img class="star" src="http://elf8848.iteye.com/images/icon_star.png" alt="收藏代码"></a></p>
    <ol class="dp-xml list-paddingleft-2" style="font-size: 1em; line-height: 1.4em; margin-bottom: 1px; padding: 2px 0px; border: 1px solid rgb(209, 215, 220); list-style-position: initial; list-style-image: initial; color: rgb(43, 145, 175);">
     <li><p><span style="color: black;"><span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&lt;</span><span class="tag-name" style="color: rgb(0, 102, 153); font-weight: bold;">mvc:default-servlet-handler</span><span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">/&gt;</span>&nbsp;&nbsp;</span></p></li>
    </ol>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);"><span style="font-size: small;"></span></p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">会把"/**" url,注册到SimpleUrlHandlerMapping的urlMap中,把对静态资源的访问由HandlerMapping转到org.springframework.web.servlet.resource.DefaultServletHttpRequestHandler处理并返回.<br>DefaultServletHttpRequestHandler使用就是各个Servlet容器自己的默认Servlet.</p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">&nbsp;</p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">&nbsp;</p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">补充说明：多个HandlerMapping的执行顺序问题：</p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">DefaultAnnotationHandlerMapping的order属性值是：0<br><br>&lt;<span style="font-size: small;">mvc:resources/</span>&nbsp;&gt;<span style="font-size: small;">自动注册的&nbsp;</span>SimpleUrlHandlerMapping<span style="font-size: small;">的order属性值是：&nbsp;</span>2147483646</p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">&nbsp;</p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);"><span style="font-size: small;">&lt;mvc:default-servlet-handler/&gt;自动注册</span>&nbsp;<span style="font-size: small;">的SimpleUrlHandlerMapping</span>&nbsp;<span style="font-size: small;">的order属性值是：</span>&nbsp;<span style="font-size: small;">2147483647</span></p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">&nbsp;</p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">&nbsp;</p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">spring会先执行order值比较小的。当访问一个a.jpg图片文件时，先通过 DefaultAnnotationHandlerMapping 来找处理器，一定是找不到的，因为我们没有叫a.jpg的Action。然后再按order值升序找，由于最后一个 SimpleUrlHandlerMapping 是匹配 "/**"的，所以一定会匹配上，就可以响应图片。</p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">&nbsp;</p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);"><em>访问一个图片，还要走层层匹配。不知性能如何？</em></p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">最后再说明一下，方案二、方案三 在访问静态资源时，如果有匹配的(近似)总拦截器，就会走拦截器。如果你在拦截中实现权限检查，要注意过滤这些对静态文件的请求。</p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">如何你的DispatcherServlet拦截 *.do这样的URL后缀，就不存上述问题了。还是有后缀方便。</p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">&nbsp;</p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">转载请注明出处：原文地址：<a href="http://elf8848.iteye.com/blog/875830" style="color: rgb(16, 138, 198);">http://elf8848.iteye.com/blog/875830</a></p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">&nbsp;</p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);"><br><strong><span style="font-size: medium;">八、请求如何映射到具体的Action中的方法？<br></span></strong>方案一：基于xml配置映射，可以利用SimpleUrlHandlerMapping、BeanNameUrlHandlerMapping进行Url映射和拦截请求。<br>配置方法略。<br>&nbsp;<br><span style="font-size: small;">方案二：基于注解映射，可以使用DefaultAnnotationHandlerMapping。</span></p>
    <p>Xml代码&nbsp;&nbsp;<a title="收藏这段代码" style="color: rgb(16, 138, 198); text-decoration: underline;"><img class="star" src="http://elf8848.iteye.com/images/icon_star.png" alt="收藏代码"></a></p>
    <ol class="dp-xml list-paddingleft-2" style="font-size: 1em; line-height: 1.4em; margin-bottom: 1px; padding: 2px 0px; border: 1px solid rgb(209, 215, 220); list-style-position: initial; list-style-image: initial; color: rgb(43, 145, 175);">
     <li><p><span style="color: black;"><span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&lt;</span><span class="tag-name" style="color: rgb(0, 102, 153); font-weight: bold;">bean</span>&nbsp;<span class="attribute" style="color: red;">class</span>=<span class="attribute-value" style="color: blue;">"org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping"</span><span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&gt;</span>&nbsp;&nbsp;<span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&lt;/</span><span class="tag-name" style="color: rgb(0, 102, 153); font-weight: bold;">bean</span><span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&gt;</span>&nbsp;&nbsp;&nbsp;</span></p></li>
    </ol>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">&nbsp;</p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);"><span style="font-size: small;">但前面我们配置了&lt;mvc:annotation-driven /&gt;，他会自动注册这个bean,就不须要我们显示的注册这个bean了。&nbsp;&nbsp;</span></p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);"><span style="font-size: small;">如何替换</span>&nbsp;<span style="font-size: small;">&lt;mvc:annotation-driven /&gt;？他到底做了什么工作，请看，最后面的 十九节&nbsp;</span><span style="font-size: small;">&lt;mvc:annotation-driven /&gt;&nbsp;</span><span style="font-size: small;">到底做了什么工作。</span></p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);"><span style="font-size: small;"><br></span></p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);"><span style="font-size: small;">&nbsp;<br>以上都可以注入interceptors，实现权限控制等前置工作。<br>我们使用第2种，基于注解来使用spring MVC</span></p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">&nbsp;</p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">&nbsp;</p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">&nbsp;<span style="font-size: small;">并在action类上使用：<br>@Controller<br>@RequestMapping("/user")</span></p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);"><span style="font-size: small;"><span style="font-size: 12px;">转载请注明出处：原文地址：<a href="http://elf8848.iteye.com/blog/875830" style="color: rgb(16, 138, 198);">http://elf8848.iteye.com/blog/875830</a>&nbsp;</span><br>&nbsp;<br>&nbsp;<br><strong><span style="font-size: medium;">九、Spring中的拦截器：<br></span></strong>Spring为我们提供了：<br>org.springframework.web.servlet.HandlerInterceptor接口，</span></p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);"><span style="font-size: small;">org.springframework.web.servlet.handler.HandlerInterceptorAdapter适配器，<br>实现这个接口或继承此类，可以非常方便的实现自己的拦截器。<br>&nbsp;<br>有以下三个方法：<br>&nbsp;<br>Action之前执行:<br>&nbsp;public boolean preHandle(HttpServletRequest request,<br>&nbsp;&nbsp; HttpServletResponse response, Object handler);<br>&nbsp;<br>生成视图之前执行<br>&nbsp;public void postHandle(HttpServletRequest request,<br>&nbsp;&nbsp; HttpServletResponse response, Object handler,<br>&nbsp;&nbsp; ModelAndView modelAndView);<br>&nbsp;<br>最后执行，可用于释放资源<br>&nbsp;public void afterCompletion(HttpServletRequest request,<br>&nbsp;&nbsp; HttpServletResponse response, Object handler, Exception ex)<br>&nbsp;<br>&nbsp;<br>分别实现预处理、后处理（调用了Service并返回ModelAndView，但未进行页面渲染）、返回处理（已经渲染了页面）&nbsp;<br>在preHandle中，可以进行编码、安全控制等处理；&nbsp;<br>在postHandle中，有机会修改ModelAndView；&nbsp;<br>在afterCompletion中，可以根据ex是否为null判断是否发生了异常，进行日志记录。&nbsp;<br>参数中的Object handler是下一个拦截器。<br><span style="font-size: 12px;">转载请注明出处：原文地址：<a href="http://elf8848.iteye.com/blog/875830" style="color: rgb(16, 138, 198);">http://elf8848.iteye.com/blog/875830</a></span></span></p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);"><span style="font-size: small;"><br><strong><span style="font-size: medium;">十、如何使用拦截器？<br></span></strong>自定义一个拦截器，要实现HandlerInterceptor接口：<br></span></p>
    <p>Java代码&nbsp;&nbsp;<a title="收藏这段代码" style="color: rgb(16, 138, 198); text-decoration: underline;"><img class="star" src="http://elf8848.iteye.com/images/icon_star.png" alt="收藏代码"></a></p>
    <ol class="dp-j list-paddingleft-2" style="font-size: 1em; line-height: 1.4em; margin-bottom: 1px; padding: 2px 0px; border: 1px solid rgb(209, 215, 220); list-style-position: initial; list-style-image: initial; color: rgb(43, 145, 175);">
     <li><p><span style="color: black;"><span class="keyword" style="color: rgb(127, 0, 85); font-weight: bold;">public</span>&nbsp;<span class="keyword" style="color: rgb(127, 0, 85); font-weight: bold;">class</span>&nbsp;MyInteceptor&nbsp;<span class="keyword" style="color: rgb(127, 0, 85); font-weight: bold;">implements</span>&nbsp;HandlerInterceptor&nbsp;{&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;">&nbsp;&nbsp;&nbsp;&nbsp;略。。。&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;">}&nbsp;&nbsp;&nbsp;&nbsp;</span></p></li>
    </ol>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">&nbsp;</p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);"><span style="font-size: small;">Spring MVC并没有总的拦截器，不能对所有的请求进行前后拦截。<br>Spring MVC的拦截器，是属于HandlerMapping级别的，可以有多个HandlerMapping ，每个HandlerMapping可以有自己的拦截器。<br>当一个请求按Order值从小到大，顺序执行HandlerMapping接口的实现类时，哪一个先有返回，那就可以结束了，后面的HandlerMapping就不走了，本道工序就完成了。就转到下一道工序了。<br>拦截器会在什么时候执行呢？ 一个请求交给一个HandlerMapping时，这个HandlerMapping先找有没有处理器来处理这个请求，如何找到了，就执行拦截器，执行完拦截后，交给目标处理器。<br>如果没有找到处理器，那么这个拦截器就不会被执行。</span></p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">&nbsp;</p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);"><br><span style="font-size: small;">在spring MVC的配置文件中配置有三种方法：</span></p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);"><br><span style="font-size: small;">方案一，（近似）总拦截器，拦截所有url</span></p>
    <p>Java代码&nbsp;&nbsp;<a title="收藏这段代码" style="color: rgb(16, 138, 198); text-decoration: underline;"><img class="star" src="http://elf8848.iteye.com/images/icon_star.png" alt="收藏代码"></a></p>
    <ol class="dp-j list-paddingleft-2" style="font-size: 1em; line-height: 1.4em; margin-bottom: 1px; padding: 2px 0px; border: 1px solid rgb(209, 215, 220); list-style-position: initial; list-style-image: initial; color: rgb(43, 145, 175);">
     <li><p><span style="color: black;">&nbsp;&nbsp;&nbsp;&lt;mvc:interceptors&gt;&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;">&nbsp;&nbsp;&nbsp;&nbsp;&lt;bean&nbsp;<span class="keyword" style="color: rgb(127, 0, 85); font-weight: bold;">class</span>=<span class="string" style="color: blue;">"com.app.mvc.MyInteceptor"</span>&nbsp;/&gt;&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;">&lt;/mvc:interceptors&gt;&nbsp;&nbsp;</span></p></li>
    </ol>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);"><span style="font-size: small;">为什么叫“近似”，前面说了，Spring没有总的拦截器。</span></p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);"><span style="font-size: small;">&lt;mvc:interceptors/&gt;会为每一个HandlerMapping，注入一个拦截器。总有一个HandlerMapping是可以找到处理器的，最多也只找到一个处理器，所以这个拦截器总会被执行的。起到了总拦截器的作用。</span></p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">如果是REST风格的URL，静态资源也会被拦截。</p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">&nbsp;</p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">&nbsp;<br><span style="font-size: small;">方案二，</span>&nbsp;<span style="font-size: small;">（近似）</span>&nbsp;<span style="font-size: small;">总拦截器，</span>&nbsp;<span style="font-size: small;">拦截匹配的URL。</span></p>
    <p>Xml代码&nbsp;&nbsp;<a title="收藏这段代码" style="color: rgb(16, 138, 198); text-decoration: underline;"><img class="star" src="http://elf8848.iteye.com/images/icon_star.png" alt="收藏代码"></a></p>
    <ol class="dp-xml list-paddingleft-2" style="font-size: 1em; line-height: 1.4em; margin-bottom: 1px; padding: 2px 0px; border: 1px solid rgb(209, 215, 220); list-style-position: initial; list-style-image: initial; color: rgb(43, 145, 175);">
     <li><p><span style="color: black;"><span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&lt;</span><span class="tag-name" style="color: rgb(0, 102, 153); font-weight: bold;">mvc:interceptors</span>&nbsp;<span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&gt;</span>&nbsp;&nbsp;&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;">&nbsp;&nbsp;<span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&lt;</span><span class="tag-name" style="color: rgb(0, 102, 153); font-weight: bold;">mvc:interceptor</span><span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&gt;</span>&nbsp;&nbsp;&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&lt;</span><span class="tag-name" style="color: rgb(0, 102, 153); font-weight: bold;">mvc:mapping</span>&nbsp;<span class="attribute" style="color: red;">path</span>=<span class="attribute-value" style="color: blue;">"/user/*"</span>&nbsp;<span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">/&gt;</span>&nbsp;<span class="comments" style="color: rgb(0, 130, 0); padding: 0px; margin: 0px; width: auto; border: 0px;">&lt;!--&nbsp;/user/*&nbsp;&nbsp;--&gt;</span>&nbsp;&nbsp;&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&lt;</span><span class="tag-name" style="color: rgb(0, 102, 153); font-weight: bold;">bean</span>&nbsp;<span class="attribute" style="color: red;">class</span>=<span class="attribute-value" style="color: blue;">"com.mvc.MyInteceptor"</span><span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&gt;</span><span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&lt;/</span><span class="tag-name" style="color: rgb(0, 102, 153); font-weight: bold;">bean</span><span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&gt;</span>&nbsp;&nbsp;&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;">&nbsp;&nbsp;&nbsp;&nbsp;<span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&lt;/</span><span class="tag-name" style="color: rgb(0, 102, 153); font-weight: bold;">mvc:interceptor</span><span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&gt;</span>&nbsp;&nbsp;&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;"><span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&lt;/</span><span class="tag-name" style="color: rgb(0, 102, 153); font-weight: bold;">mvc:interceptors</span><span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&gt;</span>&nbsp;&nbsp;&nbsp;&nbsp;</span></p></li>
    </ol>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);"><span style="font-size: small;">就是比</span>&nbsp;<span style="font-size: small;">方案一多了一个URL匹配。</span></p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">如果是REST风格的URL，静态资源也会被拦截。</p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">&nbsp;</p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">&nbsp;</p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">&nbsp;</p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);"><span style="font-size: small;">方案三,HandlerMappint上的拦截器。</span></p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">如果是REST风格的URL，静态资源就不会被拦截。因为我们精准的注入了拦截器。</p>
    <p>Xml代码&nbsp;&nbsp;<a title="收藏这段代码" style="color: rgb(16, 138, 198); text-decoration: underline;"><img class="star" src="http://elf8848.iteye.com/images/icon_star.png" alt="收藏代码"></a></p>
    <ol class="dp-xml list-paddingleft-2" style="font-size: 1em; line-height: 1.4em; margin-bottom: 1px; padding: 2px 0px; border: 1px solid rgb(209, 215, 220); list-style-position: initial; list-style-image: initial; color: rgb(43, 145, 175);">
     <li><p><span style="color: black;"><span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&lt;</span><span class="tag-name" style="color: rgb(0, 102, 153); font-weight: bold;">bean</span>&nbsp;<span class="attribute" style="color: red;">class</span>=<span class="attribute-value" style="color: blue;">"org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping"</span><span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&gt;</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;">&nbsp;<span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&lt;</span><span class="tag-name" style="color: rgb(0, 102, 153); font-weight: bold;">property</span>&nbsp;<span class="attribute" style="color: red;">name</span>=<span class="attribute-value" style="color: blue;">"interceptors"</span><span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&gt;</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&lt;</span><span class="tag-name" style="color: rgb(0, 102, 153); font-weight: bold;">list</span><span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&gt;</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&lt;</span><span class="tag-name" style="color: rgb(0, 102, 153); font-weight: bold;">bean</span>&nbsp;<span class="attribute" style="color: red;">class</span>=<span class="attribute-value" style="color: blue;">"com.mvc.MyInteceptor"</span><span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&gt;</span><span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&lt;/</span><span class="tag-name" style="color: rgb(0, 102, 153); font-weight: bold;">bean</span><span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&gt;</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&lt;/</span><span class="tag-name" style="color: rgb(0, 102, 153); font-weight: bold;">list</span><span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&gt;</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;">&nbsp;<span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&lt;/</span><span class="tag-name" style="color: rgb(0, 102, 153); font-weight: bold;">property</span><span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&gt;</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;"><span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&lt;/</span><span class="tag-name" style="color: rgb(0, 102, 153); font-weight: bold;">bean</span><span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&gt;</span>&nbsp;&nbsp;&nbsp;</span></p></li>
    </ol>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);"><span style="font-size: small;">&nbsp;</span>&nbsp;<span style="font-size: small;">如果使用了&lt;mvc:annotation-driven /&gt;，&nbsp;它会自动注册DefaultAnnotationHandlerMapping 与AnnotationMethodHandlerAdapter 这两个bean,所以就没有机会再给它注入interceptors属性，就无法指定拦截器。</span></p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);"><span style="font-size: small;">当然我们可以通过人工配置上面的两个Bean，不使用</span>&nbsp;<span style="font-size: small;">&lt;mvc:annotation-driven /&gt;，就可以</span>&nbsp;<span style="font-size: small;">给interceptors属性</span>&nbsp;<span style="font-size: small;">注入拦截器了。</span></p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">&nbsp;</p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);"><span style="font-size: small;">其实我也不建议使用</span>&nbsp;<span style="font-size: small;">&lt;mvc:annotation-driven /&gt;，而建议手动写详细的配置文件，来替代</span>&nbsp;<span style="font-size: small;">&lt;mvc:annotation-driven /&gt;，这就控制力就强了。</span></p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);"><span style="font-size: small;">如何替换</span>&nbsp;<span style="font-size: small;">&lt;mvc:annotation-driven /&gt;？他到底做了什么工作，请看，最后面的 十九节&nbsp;</span><span style="font-size: small;">&lt;mvc:annotation-driven /&gt;&nbsp;</span><span style="font-size: small;">到底做了什么工作。</span></p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">转载请注明出处：原文地址：<a href="http://elf8848.iteye.com/blog/875830" style="color: rgb(16, 138, 198);">http://elf8848.iteye.com/blog/875830</a></p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">&nbsp;</p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">&nbsp;</p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">&nbsp;</p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);"><strong><span style="font-size: medium;">十一、如何实现全局的异常处理？</span></strong></p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);"><span style="font-size: small;">在spring MVC的配置文件中：</span></p>
    <p>Xml代码&nbsp;&nbsp;<a title="收藏这段代码" style="color: rgb(16, 138, 198); text-decoration: underline;"><img class="star" src="http://elf8848.iteye.com/images/icon_star.png" alt="收藏代码"></a></p>
    <ol class="dp-xml list-paddingleft-2" style="font-size: 1em; line-height: 1.4em; margin-bottom: 1px; padding: 2px 0px; border: 1px solid rgb(209, 215, 220); list-style-position: initial; list-style-image: initial; color: rgb(43, 145, 175);">
     <li><p><span style="color: black;"><span class="comments" style="color: rgb(0, 130, 0); padding: 0px; margin: 0px; width: auto; border: 0px;">&lt;!--&nbsp;总错误处理--&gt;</span>&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;"><span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&lt;</span><span class="tag-name" style="color: rgb(0, 102, 153); font-weight: bold;">bean</span>&nbsp;<span class="attribute" style="color: red;">id</span>=<span class="attribute-value" style="color: blue;">"exceptionResolver"</span>&nbsp;<span class="attribute" style="color: red;">class</span>=<span class="attribute-value" style="color: blue;">"org.springframework.web.servlet.handler.SimpleMappingExceptionResolver"</span><span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&gt;</span>&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;">&nbsp;&nbsp;&nbsp;&nbsp;<span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&lt;</span><span class="tag-name" style="color: rgb(0, 102, 153); font-weight: bold;">property</span>&nbsp;<span class="attribute" style="color: red;">name</span>=<span class="attribute-value" style="color: blue;">"defaultErrorView"</span><span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&gt;</span>&nbsp;&nbsp;&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&lt;</span><span class="tag-name" style="color: rgb(0, 102, 153); font-weight: bold;">value</span><span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&gt;</span>/error/error<span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&lt;/</span><span class="tag-name" style="color: rgb(0, 102, 153); font-weight: bold;">value</span><span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&gt;</span>&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;">&nbsp;&nbsp;&nbsp;&nbsp;<span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&lt;/</span><span class="tag-name" style="color: rgb(0, 102, 153); font-weight: bold;">property</span><span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&gt;</span>&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;">&nbsp;&nbsp;&nbsp;&nbsp;<span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&lt;</span><span class="tag-name" style="color: rgb(0, 102, 153); font-weight: bold;">property</span>&nbsp;<span class="attribute" style="color: red;">name</span>=<span class="attribute-value" style="color: blue;">"defaultStatusCode"</span><span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&gt;</span>&nbsp;&nbsp;&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&lt;</span><span class="tag-name" style="color: rgb(0, 102, 153); font-weight: bold;">value</span><span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&gt;</span>500<span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&lt;/</span><span class="tag-name" style="color: rgb(0, 102, 153); font-weight: bold;">value</span><span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&gt;</span>&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;">&nbsp;&nbsp;&nbsp;&nbsp;<span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&lt;/</span><span class="tag-name" style="color: rgb(0, 102, 153); font-weight: bold;">property</span><span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&gt;</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;"><span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&lt;</span><span class="tag-name" style="color: rgb(0, 102, 153); font-weight: bold;">property</span>&nbsp;<span class="attribute" style="color: red;">name</span>=<span class="attribute-value" style="color: blue;">"warnLogCategory"</span><span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&gt;</span>&nbsp;&nbsp;&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&lt;</span><span class="tag-name" style="color: rgb(0, 102, 153); font-weight: bold;">value</span><span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&gt;</span>org.springframework.web.servlet.handler.SimpleMappingExceptionResolver<span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&lt;/</span><span class="tag-name" style="color: rgb(0, 102, 153); font-weight: bold;">value</span><span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&gt;</span>&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;">&nbsp;&nbsp;&nbsp;&nbsp;<span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&lt;/</span><span class="tag-name" style="color: rgb(0, 102, 153); font-weight: bold;">property</span><span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&gt;</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;"><span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&lt;/</span><span class="tag-name" style="color: rgb(0, 102, 153); font-weight: bold;">bean</span><span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&gt;</span>&nbsp;&nbsp;&nbsp;</span></p></li>
    </ol>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">&nbsp;</p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);"><span style="font-size: small;">这里主要的类是SimpleMappingExceptionResolver类，和他的父类AbstractHandlerExceptionResolver类。</span></p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);"><span style="font-size: small;">具体可以配置哪些属性，我是通过查看源码知道的。</span></p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);"><span style="font-size: small;">你也可以实现HandlerExceptionResolver接口，写一个自己的异常处理程序。spring的扩展性是很好的。</span></p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);"><span style="font-size: small;">&nbsp;</span></p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);"><span style="font-size: small;">&nbsp;</span></p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);"><span style="font-size: small;">通过SimpleMappingExceptionResolver我们可以将不同的异常映射到不同的jsp页面（通过exceptionMappings属性的配置）。</span></p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);"><span style="font-size: small;">&nbsp;</span></p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);"><span style="font-size: small;">同时我们也可以为所有的异常指定一个默认的异常提示页面（通过defaultErrorView属性的配置），如果所抛出的异常在exceptionMappings中没有对应的映射，则Spring将用此默认配置显示异常信息。</span></p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);"><span style="font-size: small;">注意这里配置的异常显示界面均仅包括主文件名，至于文件路径和后缀已经在viewResolver中指定。如/error/error表示/error/error.jsp</span></p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">&nbsp;</p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);"><span style="font-size: small;">&nbsp;</span></p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);"><span style="font-size: small;">显示错误的jsp页面：</span></p>
    <p>Html代码&nbsp;&nbsp;<a title="收藏这段代码" style="color: rgb(16, 138, 198); text-decoration: underline;"><img class="star" src="http://elf8848.iteye.com/images/icon_star.png" alt="收藏代码"></a></p>
    <ol class="dp-xml list-paddingleft-2" style="font-size: 1em; line-height: 1.4em; margin-bottom: 1px; padding: 2px 0px; border: 1px solid rgb(209, 215, 220); list-style-position: initial; list-style-image: initial; color: rgb(43, 145, 175);">
     <li><p><span style="color: black;"><span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&lt;</span>%@&nbsp;page&nbsp;<span class="attribute" style="color: red;">language</span>=<span class="attribute-value" style="color: blue;">"java"</span>&nbsp;<span class="attribute" style="color: red;">contentType</span>=<span class="attribute-value" style="color: blue;">"text/html;&nbsp;charset=GBK"</span>&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;">&nbsp;&nbsp;&nbsp;&nbsp;<span class="attribute" style="color: red;">pageEncoding</span>=<span class="attribute-value" style="color: blue;">"GBK"</span>%<span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&gt;</span>&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;"><span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&lt;</span>%@&nbsp;page&nbsp;<span class="attribute" style="color: red;">import</span>=<span class="attribute-value" style="color: blue;">"java.lang.Exception"</span>%<span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&gt;</span>&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;">&lt;!DOCTYPE&nbsp;html&nbsp;PUBLIC&nbsp;"-//W3C//DTD&nbsp;HTML&nbsp;4.01&nbsp;Transitional//EN"&nbsp;"http://www.w3.org/TR/html4/loose.dtd"<span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&gt;</span>&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;"><span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&lt;</span><span class="tag-name" style="color: rgb(0, 102, 153); font-weight: bold;">html</span><span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&gt;</span>&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;"><span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&lt;</span><span class="tag-name" style="color: rgb(0, 102, 153); font-weight: bold;">head</span><span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&gt;</span>&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;"><span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&lt;</span><span class="tag-name" style="color: rgb(0, 102, 153); font-weight: bold;">meta</span>&nbsp;<span class="attribute" style="color: red;">http-equiv</span>=<span class="attribute-value" style="color: blue;">"Content-Type"</span>&nbsp;<span class="attribute" style="color: red;">content</span>=<span class="attribute-value" style="color: blue;">"text/html;&nbsp;charset=GBK"</span><span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&gt;</span>&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;"><span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&lt;</span><span class="tag-name" style="color: rgb(0, 102, 153); font-weight: bold;">title</span><span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&gt;</span>错误页面<span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&lt;/</span><span class="tag-name" style="color: rgb(0, 102, 153); font-weight: bold;">title</span><span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&gt;</span>&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;"><span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&lt;/</span><span class="tag-name" style="color: rgb(0, 102, 153); font-weight: bold;">head</span><span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&gt;</span>&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;"><span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&lt;</span><span class="tag-name" style="color: rgb(0, 102, 153); font-weight: bold;">body</span><span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&gt;</span>&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;"><span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&lt;</span><span class="tag-name" style="color: rgb(0, 102, 153); font-weight: bold;">h1</span><span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&gt;</span>出错了<span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&lt;/</span><span class="tag-name" style="color: rgb(0, 102, 153); font-weight: bold;">h1</span><span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&gt;</span>&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;"><span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&lt;</span>%&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;">Exception&nbsp;<span class="attribute" style="color: red;">e</span>&nbsp;=&nbsp;(Exception)request.getAttribute("exception");&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;">out.print(e.getMessage());&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;">%<span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&gt;</span>&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;"><span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&lt;/</span><span class="tag-name" style="color: rgb(0, 102, 153); font-weight: bold;">body</span><span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&gt;</span>&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;"><span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&lt;/</span><span class="tag-name" style="color: rgb(0, 102, 153); font-weight: bold;">html</span><span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&gt;</span>&nbsp;&nbsp;</span></p></li>
    </ol>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);"><span style="font-size: small;">其中一句：request.getAttribute("exception")，key是exception，也是在SimpleMappingExceptionResolver类默认指定的，是可能通过配置文件修改这个值的，大家可以去看源码。</span></p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">&nbsp;</p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">&nbsp;</p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">&nbsp;</p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);"><strong><span style="font-size: medium;">十二、如何把全局异常记录到日志中？</span></strong></p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);"><span style="font-size: small;">在前的配置中，其中有一个属性warnLogCategory，值是“SimpleMappingExceptionResolver类的全限定名”。我是在SimpleMappingExceptionResolver类父类AbstractHandlerExceptionResolver类中找到这个属性的。查看源码后得知：如果warnLogCategory不为空，spring就会使用apache的org.apache.commons.logging.Log日志工具，记录这个异常，级别是warn。</span></p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);"><span style="font-size: small;">值：“org.springframework.web.servlet.handler.SimpleMappingExceptionResolver”，是“SimpleMappingExceptionResolver类的全限定名”。这个值不是随便写的。</span>&nbsp;<span style="font-size: small;">&nbsp;因为我在log4j的配置文件中还要加入log4j.logger.org.springframework.web.servlet.handler.SimpleMappingExceptionResolver=WARN，保证这个级别是warn的日志一定会被记录，即使log4j的根日志级别是ERROR。</span></p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">转载请注明出处：原文地址：<a href="http://elf8848.iteye.com/blog/875830" style="color: rgb(16, 138, 198);">http://elf8848.iteye.com/blog/875830</a></p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">&nbsp;</p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">&nbsp;</p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">&nbsp;</p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">&nbsp;<strong><span style="font-size: medium;">十三、如何给spring3 MVC中的Action做JUnit单元测试？</span></strong></p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);"><span style="font-size: small;">&nbsp;使用了spring3 MVC后，给action做单元测试变得很方便，我以前从来不给action写单元测试的，现在可以根据情况写一些了。</span></p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">&nbsp;不用给每个Action都写单元测试吧，自己把握吧。</p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);"><span style="font-size: small;">&nbsp;</span></p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);"><span style="font-size: small;">&nbsp;JUnitActionBase类是所有JUnit的测试类的父类</span></p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);"><span style="font-size: small;"></span></p>
    <p>Java代码&nbsp;&nbsp;<a title="收藏这段代码" style="color: rgb(16, 138, 198); text-decoration: underline;"><img class="star" src="http://elf8848.iteye.com/images/icon_star.png" alt="收藏代码"></a></p>
    <ol class="dp-j list-paddingleft-2" style="font-size: 1em; line-height: 1.4em; margin-bottom: 1px; padding: 2px 0px; border: 1px solid rgb(209, 215, 220); list-style-position: initial; list-style-image: initial; color: rgb(43, 145, 175);">
     <li><p><span style="color: black;"><span class="keyword" style="color: rgb(127, 0, 85); font-weight: bold;">package</span>&nbsp;test;&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;"><span class="keyword" style="color: rgb(127, 0, 85); font-weight: bold;">import</span>&nbsp;javax.servlet.http.HttpServletRequest;&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;"><span class="keyword" style="color: rgb(127, 0, 85); font-weight: bold;">import</span>&nbsp;javax.servlet.http.HttpServletResponse;&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;"><span class="keyword" style="color: rgb(127, 0, 85); font-weight: bold;">import</span>&nbsp;org.junit.BeforeClass;&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;"><span class="keyword" style="color: rgb(127, 0, 85); font-weight: bold;">import</span>&nbsp;org.springframework.mock.web.MockServletContext;&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;"><span class="keyword" style="color: rgb(127, 0, 85); font-weight: bold;">import</span>&nbsp;org.springframework.web.context.WebApplicationContext;&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;"><span class="keyword" style="color: rgb(127, 0, 85); font-weight: bold;">import</span>&nbsp;org.springframework.web.context.support.XmlWebApplicationContext;&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;"><span class="keyword" style="color: rgb(127, 0, 85); font-weight: bold;">import</span>&nbsp;org.springframework.web.servlet.HandlerAdapter;&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;"><span class="keyword" style="color: rgb(127, 0, 85); font-weight: bold;">import</span>&nbsp;org.springframework.web.servlet.HandlerExecutionChain;&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;"><span class="keyword" style="color: rgb(127, 0, 85); font-weight: bold;">import</span>&nbsp;org.springframework.web.servlet.HandlerMapping;&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;"><span class="keyword" style="color: rgb(127, 0, 85); font-weight: bold;">import</span>&nbsp;org.springframework.web.servlet.ModelAndView;&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;"><span class="keyword" style="color: rgb(127, 0, 85); font-weight: bold;">import</span>&nbsp;org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter;&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;"><span class="keyword" style="color: rgb(127, 0, 85); font-weight: bold;">import</span>&nbsp;org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping;&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;"><span class="comment" style="color: rgb(0, 130, 0); padding: 0px; margin: 0px; width: auto; border: 0px;">/**&nbsp;</span>&nbsp;</span></p></li>
     <li><p><span style="color: black;"><span class="comment" style="color: rgb(0, 130, 0); padding: 0px; margin: 0px; width: auto; border: 0px;">*&nbsp;说明：&nbsp;JUnit测试action时使用的基类</span>&nbsp;</span></p></li>
     <li><p><span style="color: black;"><span class="comment" style="color: rgb(0, 130, 0); padding: 0px; margin: 0px; width: auto; border: 0px;">*&nbsp;</span>&nbsp;</span></p></li>
     <li><p><span style="color: black;"><span class="comment" style="color: rgb(0, 130, 0); padding: 0px; margin: 0px; width: auto; border: 0px;">*&nbsp;@author&nbsp;&nbsp;赵磊</span>&nbsp;</span></p></li>
     <li><p><span style="color: black;"><span class="comment" style="color: rgb(0, 130, 0); padding: 0px; margin: 0px; width: auto; border: 0px;">*&nbsp;@version&nbsp;创建时间：2011-2-2&nbsp;下午10:27:03&nbsp;&nbsp;</span>&nbsp;</span></p></li>
     <li><p><span style="color: black;"><span class="comment" style="color: rgb(0, 130, 0); padding: 0px; margin: 0px; width: auto; border: 0px;">*/</span>&nbsp;&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;"><span class="keyword" style="color: rgb(127, 0, 85); font-weight: bold;">public</span>&nbsp;<span class="keyword" style="color: rgb(127, 0, 85); font-weight: bold;">class</span>&nbsp;JUnitActionBase&nbsp;{&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;">&nbsp;&nbsp;&nbsp;&nbsp;<span class="keyword" style="color: rgb(127, 0, 85); font-weight: bold;">private</span>&nbsp;<span class="keyword" style="color: rgb(127, 0, 85); font-weight: bold;">static</span>&nbsp;HandlerMapping&nbsp;handlerMapping;&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;">&nbsp;&nbsp;&nbsp;&nbsp;<span class="keyword" style="color: rgb(127, 0, 85); font-weight: bold;">private</span>&nbsp;<span class="keyword" style="color: rgb(127, 0, 85); font-weight: bold;">static</span>&nbsp;HandlerAdapter&nbsp;handlerAdapter;&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;">&nbsp;&nbsp;&nbsp;&nbsp;<span class="comment" style="color: rgb(0, 130, 0); padding: 0px; margin: 0px; width: auto; border: 0px;">/**</span>&nbsp;</span></p></li>
     <li><p><span style="color: black;"><span class="comment" style="color: rgb(0, 130, 0); padding: 0px; margin: 0px; width: auto; border: 0px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;读取spring3&nbsp;MVC配置文件</span>&nbsp;</span></p></li>
     <li><p><span style="color: black;"><span class="comment" style="color: rgb(0, 130, 0); padding: 0px; margin: 0px; width: auto; border: 0px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*/</span>&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;">&nbsp;&nbsp;&nbsp;&nbsp;<span class="annotation" style="color: rgb(100, 100, 100);">@BeforeClass</span>&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;">&nbsp;<span class="keyword" style="color: rgb(127, 0, 85); font-weight: bold;">public</span>&nbsp;<span class="keyword" style="color: rgb(127, 0, 85); font-weight: bold;">static</span>&nbsp;<span class="keyword" style="color: rgb(127, 0, 85); font-weight: bold;">void</span>&nbsp;setUp()&nbsp;{&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="keyword" style="color: rgb(127, 0, 85); font-weight: bold;">if</span>&nbsp;(handlerMapping&nbsp;==&nbsp;<span class="keyword" style="color: rgb(127, 0, 85); font-weight: bold;">null</span>)&nbsp;{&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;String[]&nbsp;configs&nbsp;=&nbsp;{&nbsp;<span class="string" style="color: blue;">"file:src/springConfig/springMVC.xml"</span>&nbsp;};&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;XmlWebApplicationContext&nbsp;context&nbsp;=&nbsp;<span class="keyword" style="color: rgb(127, 0, 85); font-weight: bold;">new</span>&nbsp;XmlWebApplicationContext();&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;context.setConfigLocations(configs);&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;MockServletContext&nbsp;msc&nbsp;=&nbsp;<span class="keyword" style="color: rgb(127, 0, 85); font-weight: bold;">new</span>&nbsp;MockServletContext();&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;context.setServletContext(msc);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;context.refresh();&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;msc.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE,&nbsp;context);&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;handlerMapping&nbsp;=&nbsp;(HandlerMapping)&nbsp;context&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.getBean(DefaultAnnotationHandlerMapping.<span class="keyword" style="color: rgb(127, 0, 85); font-weight: bold;">class</span>);&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;handlerAdapter&nbsp;=&nbsp;(HandlerAdapter)&nbsp;context.getBean(context.getBeanNamesForType(AnnotationMethodHandlerAdapter.<span class="keyword" style="color: rgb(127, 0, 85); font-weight: bold;">class</span>)[<span class="number" style="color: rgb(192, 0, 0);">0</span>]);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;">&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;">&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;">&nbsp;&nbsp;&nbsp;&nbsp;<span class="comment" style="color: rgb(0, 130, 0); padding: 0px; margin: 0px; width: auto; border: 0px;">/**</span>&nbsp;</span></p></li>
     <li><p><span style="color: black;"><span class="comment" style="color: rgb(0, 130, 0); padding: 0px; margin: 0px; width: auto; border: 0px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;执行request对象请求的action</span>&nbsp;</span></p></li>
     <li><p><span style="color: black;"><span class="comment" style="color: rgb(0, 130, 0); padding: 0px; margin: 0px; width: auto; border: 0px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;</span>&nbsp;</span></p></li>
     <li><p><span style="color: black;"><span class="comment" style="color: rgb(0, 130, 0); padding: 0px; margin: 0px; width: auto; border: 0px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;@param&nbsp;request</span>&nbsp;</span></p></li>
     <li><p><span style="color: black;"><span class="comment" style="color: rgb(0, 130, 0); padding: 0px; margin: 0px; width: auto; border: 0px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;@param&nbsp;response</span>&nbsp;</span></p></li>
     <li><p><span style="color: black;"><span class="comment" style="color: rgb(0, 130, 0); padding: 0px; margin: 0px; width: auto; border: 0px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;@return</span>&nbsp;</span></p></li>
     <li><p><span style="color: black;"><span class="comment" style="color: rgb(0, 130, 0); padding: 0px; margin: 0px; width: auto; border: 0px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;@throws&nbsp;Exception</span>&nbsp;</span></p></li>
     <li><p><span style="color: black;"><span class="comment" style="color: rgb(0, 130, 0); padding: 0px; margin: 0px; width: auto; border: 0px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*/</span>&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;">&nbsp;&nbsp;&nbsp;&nbsp;<span class="keyword" style="color: rgb(127, 0, 85); font-weight: bold;">public</span>&nbsp;ModelAndView&nbsp;excuteAction(HttpServletRequest&nbsp;request,&nbsp;HttpServletResponse&nbsp;response)&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;">&nbsp;<span class="keyword" style="color: rgb(127, 0, 85); font-weight: bold;">throws</span>&nbsp;Exception&nbsp;{&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;HandlerExecutionChain&nbsp;chain&nbsp;=&nbsp;handlerMapping.getHandler(request);&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="keyword" style="color: rgb(127, 0, 85); font-weight: bold;">final</span>&nbsp;ModelAndView&nbsp;model&nbsp;=&nbsp;handlerAdapter.handle(request,&nbsp;response,&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;chain.getHandler());&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="keyword" style="color: rgb(127, 0, 85); font-weight: bold;">return</span>&nbsp;model;&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;">&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;">}&nbsp;&nbsp;</span></p></li>
    </ol>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);"><span style="font-size: small;"></span></p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">&nbsp;</p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">&nbsp;</p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);"><span style="font-size: small;">这是个JUnit测试类，我们可以new Request对象，来参与测试，太方便了。给request指定访问的URL，就可以请求目标Action了。</span></p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">&nbsp;</p>
    <p>Java代码&nbsp;&nbsp;<a title="收藏这段代码" style="color: rgb(16, 138, 198); text-decoration: underline;"><img class="star" src="http://elf8848.iteye.com/images/icon_star.png" alt="收藏代码"></a></p>
    <ol class="dp-j list-paddingleft-2" style="font-size: 1em; line-height: 1.4em; margin-bottom: 1px; padding: 2px 0px; border: 1px solid rgb(209, 215, 220); list-style-position: initial; list-style-image: initial; color: rgb(43, 145, 175);">
     <li><p><span style="color: black;"><span class="keyword" style="color: rgb(127, 0, 85); font-weight: bold;">package</span>&nbsp;test.com.app.user;&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;"><span class="keyword" style="color: rgb(127, 0, 85); font-weight: bold;">import</span>&nbsp;org.junit.Assert;&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;"><span class="keyword" style="color: rgb(127, 0, 85); font-weight: bold;">import</span>&nbsp;org.junit.Test;&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;"><span class="keyword" style="color: rgb(127, 0, 85); font-weight: bold;">import</span>&nbsp;org.springframework.mock.web.MockHttpServletRequest;&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;"><span class="keyword" style="color: rgb(127, 0, 85); font-weight: bold;">import</span>&nbsp;org.springframework.mock.web.MockHttpServletResponse;&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;"><span class="keyword" style="color: rgb(127, 0, 85); font-weight: bold;">import</span>&nbsp;org.springframework.web.servlet.ModelAndView;&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;">&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;"><span class="keyword" style="color: rgb(127, 0, 85); font-weight: bold;">import</span>&nbsp;test.JUnitActionBase;&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;">&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;"><span class="comment" style="color: rgb(0, 130, 0); padding: 0px; margin: 0px; width: auto; border: 0px;">/**&nbsp;</span>&nbsp;</span></p></li>
     <li><p><span style="color: black;"><span class="comment" style="color: rgb(0, 130, 0); padding: 0px; margin: 0px; width: auto; border: 0px;">*&nbsp;说明：&nbsp;测试OrderAction的例子</span>&nbsp;</span></p></li>
     <li><p><span style="color: black;"><span class="comment" style="color: rgb(0, 130, 0); padding: 0px; margin: 0px; width: auto; border: 0px;">*&nbsp;</span>&nbsp;</span></p></li>
     <li><p><span style="color: black;"><span class="comment" style="color: rgb(0, 130, 0); padding: 0px; margin: 0px; width: auto; border: 0px;">*&nbsp;@author&nbsp;&nbsp;赵磊&nbsp;</span>&nbsp;</span></p></li>
     <li><p><span style="color: black;"><span class="comment" style="color: rgb(0, 130, 0); padding: 0px; margin: 0px; width: auto; border: 0px;">*&nbsp;@version&nbsp;创建时间：2011-2-2&nbsp;下午10:26:55&nbsp;&nbsp;</span>&nbsp;</span></p></li>
     <li><p><span style="color: black;"><span class="comment" style="color: rgb(0, 130, 0); padding: 0px; margin: 0px; width: auto; border: 0px;">*/</span>&nbsp;&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;">&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;"><span class="keyword" style="color: rgb(127, 0, 85); font-weight: bold;">public</span>&nbsp;<span class="keyword" style="color: rgb(127, 0, 85); font-weight: bold;">class</span>&nbsp;TestOrderAction&nbsp;<span class="keyword" style="color: rgb(127, 0, 85); font-weight: bold;">extends</span>&nbsp;JUnitActionBase&nbsp;{&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;">&nbsp;&nbsp;&nbsp;&nbsp;<span class="annotation" style="color: rgb(100, 100, 100);">@Test</span>&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;">&nbsp;&nbsp;&nbsp;&nbsp;<span class="keyword" style="color: rgb(127, 0, 85); font-weight: bold;">public</span>&nbsp;<span class="keyword" style="color: rgb(127, 0, 85); font-weight: bold;">void</span>&nbsp;testAdd()&nbsp;<span class="keyword" style="color: rgb(127, 0, 85); font-weight: bold;">throws</span>&nbsp;Exception&nbsp;{&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;">&nbsp;&nbsp;&nbsp;&nbsp;MockHttpServletRequest&nbsp;request&nbsp;=&nbsp;<span class="keyword" style="color: rgb(127, 0, 85); font-weight: bold;">new</span>&nbsp;MockHttpServletRequest();&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;MockHttpServletResponse&nbsp;response&nbsp;=&nbsp;<span class="keyword" style="color: rgb(127, 0, 85); font-weight: bold;">new</span>&nbsp;MockHttpServletResponse();&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;request.setServletPath(<span class="string" style="color: blue;">"/order/add"</span>);&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;request.addParameter(<span class="string" style="color: blue;">"id"</span>,&nbsp;<span class="string" style="color: blue;">"1002"</span>);&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;request.addParameter(<span class="string" style="color: blue;">"date"</span>,&nbsp;<span class="string" style="color: blue;">"2010-12-30"</span>);&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;request.setMethod(<span class="string" style="color: blue;">"POST"</span>);&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="comment" style="color: rgb(0, 130, 0); padding: 0px; margin: 0px; width: auto; border: 0px;">//&nbsp;执行URI对应的action</span>&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="keyword" style="color: rgb(127, 0, 85); font-weight: bold;">final</span>&nbsp;ModelAndView&nbsp;mav&nbsp;=&nbsp;<span class="keyword" style="color: rgb(127, 0, 85); font-weight: bold;">this</span>.excuteAction(request,&nbsp;response);&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="comment" style="color: rgb(0, 130, 0); padding: 0px; margin: 0px; width: auto; border: 0px;">//&nbsp;Assert&nbsp;logic</span>&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Assert.assertEquals(<span class="string" style="color: blue;">"order/add"</span>,&nbsp;mav.getViewName());&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;String&nbsp;msg=(String)request.getAttribute(<span class="string" style="color: blue;">"msg"</span>);&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.println(msg);&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;">&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;">}&nbsp;&nbsp;</span></p></li>
    </ol>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);"><span style="font-size: small;">&nbsp;<strong>需要说明一下</strong>&nbsp;：由于当前最想版本的Spring(Test) 3.0.5还不支持@ContextConfiguration的注解式context file注入，所以还需要写个setUp处理下，否则类似于Tiles的加载过程会有错误，因为没有ServletContext。3.1的版本应该有更好的解决方案，</span></p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);"><span style="font-size: small;">参见：</span>&nbsp;<a href="https://jira.springsource.org/browse/SPR-5243" style="color: rgb(16, 138, 198);"><span style="color: rgb(0, 102, 153); font-size: small;">https://jira.springsource.org/browse/SPR-5243</span>&nbsp;</a><span style="font-size: small;">。</span></p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">参考 ：<a href="http://www.iteye.com/topic/828513" style="color: rgb(16, 138, 198);">http://www.iteye.com/topic/828513</a></p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">&nbsp;</p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">&nbsp;</p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">&nbsp;</p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">&nbsp;</p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">&nbsp;<span style="font-size: medium;"><strong>十四、转发与重定向</strong></span></p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);"><span style="font-size: small;">可以通过redirect/forward:url方式转到另一个Action进行连续的处理。</span></p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);"><span style="font-size: small;">可以通过redirect:url 防止表单重复提交</span>&nbsp;<span style="font-size: small;">。</span></p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);"><span style="font-size: small;">写法如下：</span></p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);"><span style="font-size: small;">return "forward:/order/add";</span></p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);"><span style="font-size: small;">return "redirect:/index.jsp";</span></p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">转载请注明出处：原文地址：<a href="http://elf8848.iteye.com/blog/875830" style="color: rgb(16, 138, 198);">http://elf8848.iteye.com/blog/875830</a></p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">&nbsp;</p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">&nbsp;</p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);"><strong><span style="font-size: small;">带参数重定向--RedirectAttributes</span></strong></p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">用户保存或修改后，为了防止用户刷新浏览器(F5)导致表单重复提交，一般在保存或修改操作之后会redirect到一个结果页面（不是forward），同时携带参数，如操作成功的提示信息。因为是Redirect，Request里的attribute不会传递过去。Spring在3.1才提供了这个能力--RedirectAttributes。 反复按F5，操作成功的提示信息也不会再次出来（总共只出现一次），效果很理想。</p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">&nbsp;</p>
    <p>Java代码&nbsp;&nbsp;<a title="收藏这段代码" style="color: rgb(16, 138, 198); text-decoration: underline;"><img class="star" src="http://elf8848.iteye.com/images/icon_star.png" alt="收藏代码"></a></p>
    <ol class="dp-j list-paddingleft-2" style="font-size: 1em; line-height: 1.4em; margin-bottom: 1px; padding: 2px 0px; border: 1px solid rgb(209, 215, 220); list-style-position: initial; list-style-image: initial; color: rgb(43, 145, 175);">
     <li><p><span style="color: black;"><span class="keyword" style="color: rgb(127, 0, 85); font-weight: bold;">public</span>&nbsp;String&nbsp;save(<span class="annotation" style="color: rgb(100, 100, 100);">@ModelAttribute</span>(<span class="string" style="color: blue;">"group"</span>)&nbsp;Group&nbsp;group,&nbsp;RedirectAttributes&nbsp;redirectAttributes)&nbsp;{&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;">&nbsp;&nbsp;&nbsp;&nbsp;accountManager.saveGroup(group);&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;">&nbsp;&nbsp;&nbsp;&nbsp;redirectAttributes.addFlashAttribute(<span class="string" style="color: blue;">"message"</span>,&nbsp;<span class="string" style="color: blue;">"操作成功"</span>);&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;">&nbsp;&nbsp;&nbsp;&nbsp;<span class="keyword" style="color: rgb(127, 0, 85); font-weight: bold;">return</span>&nbsp;<span class="string" style="color: blue;">"redirect:/account/group/"</span>;&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;">}&nbsp;&nbsp;</span></p></li>
    </ol>
    <p><span style="font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; background-color: rgb(255, 255, 255);">&nbsp;</span></p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">&nbsp;</p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">&nbsp;</p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);"><span style="font-size: medium;"><strong>&nbsp;十五、处理ajax请求</strong></span></p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">&nbsp;</p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);"><span style="font-size: small;">1、引入下面两个jar包，我用的是1.7.2，好像1.4.2版本以上都可以，下载地址：</span><a href="http://wiki.fasterxml.com/JacksonDownload" style="color: rgb(16, 138, 198);"><span style="font-size: small;">http://wiki.fasterxml.com/JacksonDownload</span></a></p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);"><span style="font-size: small;">jackson-core-asl-1.7.2.jar&nbsp;</span></p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);"><span style="font-size: small;">jackson-mapper-asl-1.7.2.jar</span></p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">&nbsp;</p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);"><span style="font-size: small;">2、spring的配置文件中要有这一行，才能使用到spring内置支持的json转换。如果你手工把POJO转成json就可以不须要使用spring内置支持的json转换。</span></p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);"><span style="font-size: small;">&lt;mvc:annotation-driven /&gt;</span></p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">&nbsp;</p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);"><span style="font-size: small;">3、使用@ResponseBody注解</span></p>
    <p>Java代码&nbsp;&nbsp;<a title="收藏这段代码" style="color: rgb(16, 138, 198); text-decoration: underline;"><img class="star" src="http://elf8848.iteye.com/images/icon_star.png" alt="收藏代码"></a></p>
    <ol class="dp-j list-paddingleft-2" style="font-size: 1em; line-height: 1.4em; margin-bottom: 1px; padding: 2px 0px; border: 1px solid rgb(209, 215, 220); list-style-position: initial; list-style-image: initial; color: rgb(43, 145, 175);">
     <li><p><span style="color: black;"><span class="comment" style="color: rgb(0, 130, 0); padding: 0px; margin: 0px; width: auto; border: 0px;">/**</span>&nbsp;</span></p></li>
     <li><p><span style="color: black;"><span class="comment" style="color: rgb(0, 130, 0); padding: 0px; margin: 0px; width: auto; border: 0px;">&nbsp;*&nbsp;ajax测试</span>&nbsp;</span></p></li>
     <li><p><span style="color: black;"><span class="comment" style="color: rgb(0, 130, 0); padding: 0px; margin: 0px; width: auto; border: 0px;">*&nbsp;http://127.0.0.1/mvc/order/ajax</span>&nbsp;</span></p></li>
     <li><p><span style="color: black;"><span class="comment" style="color: rgb(0, 130, 0); padding: 0px; margin: 0px; width: auto; border: 0px;">&nbsp;*/</span>&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;">&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;"><span class="annotation" style="color: rgb(100, 100, 100);">@RequestMapping</span>(<span class="string" style="color: blue;">"/ajax"</span>)&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;"><span class="annotation" style="color: rgb(100, 100, 100);">@ResponseBody</span>&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;"><span class="keyword" style="color: rgb(127, 0, 85); font-weight: bold;">public</span>&nbsp;Object&nbsp;ajax(HttpServletRequest&nbsp;request){&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;">&nbsp;&nbsp;&nbsp;&nbsp;List&lt;String&gt;&nbsp;list=<span class="keyword" style="color: rgb(127, 0, 85); font-weight: bold;">new</span>&nbsp;ArrayList&lt;String&gt;();&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;">&nbsp;&nbsp;&nbsp;&nbsp;list.add(<span class="string" style="color: blue;">"电视"</span>);&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;">nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;list.add(<span class="string" style="color: blue;">"洗衣机"</span>);&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;">&nbsp;&nbsp;&nbsp;&nbsp;list.add(<span class="string" style="color: blue;">"冰箱"</span>);&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;">&nbsp;&nbsp;&nbsp;&nbsp;list.add(<span class="string" style="color: blue;">"电脑"</span>);&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;">&nbsp;&nbsp;&nbsp;&nbsp;list.add(<span class="string" style="color: blue;">"汽车"</span>);&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;">&nbsp;&nbsp;&nbsp;&nbsp;list.add(<span class="string" style="color: blue;">"空调"</span>);&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;">&nbsp;&nbsp;&nbsp;&nbsp;list.add(<span class="string" style="color: blue;">"自行车"</span>);&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;">&nbsp;&nbsp;&nbsp;&nbsp;list.add(<span class="string" style="color: blue;">"饮水机"</span>);&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;">&nbsp;&nbsp;&nbsp;&nbsp;list.add(<span class="string" style="color: blue;">"热水器"</span>);&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;">&nbsp;&nbsp;&nbsp;&nbsp;<span class="keyword" style="color: rgb(127, 0, 85); font-weight: bold;">return</span>&nbsp;list;&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;">}&nbsp;&nbsp;</span></p></li>
    </ol>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">&nbsp;</p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">转载请注明出处：原文地址：<a href="http://elf8848.iteye.com/blog/875830" style="color: rgb(16, 138, 198);">http://elf8848.iteye.com/blog/875830</a></p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">&nbsp;</p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">&nbsp;</p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">&nbsp;</p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);"><span style="font-size: medium;"><strong>十六、关于写几个配置文件的说明</strong>&nbsp;</span><br><br>我看到有的人把配置文件写两份：<br>一个是原有的applicationContext.xml，这个文件从spring2.0-2.5时一直在使用。<br>别一个是新加的spring MVC的配置文件。<br>其实这两个文件是可以写成一个文件的，springMVC相关的配置，数据源，事务相关配置可以都写再一个配置文件中。<br>本例子中只使用了一个spring配置文件叫“springMVC.xml”。<br>就不要再多配置一个applicationContext.xml文件了。<br>web.xml文件中也不要再配置org.springframework.web.context.ContextLoaderListener的listener了。<br>写两个配置文件一般就会导致扫描两次，一定要精确控制扫描的包名，做到不重复扫描。<br><br>写两个配置文件还出现事务不好使的现象，是当把@Transactional写有Action层时出现的。</p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">是因为父子上下文的原因，请参看前的 第五节 父子上下文，里面有说明 。原因是父上下文不能访问子上下文。</p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">&nbsp;</p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">&nbsp;</p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">&nbsp;</p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);"><span style="font-size: medium;"><strong>十七、如何取得Spring管理的bean</strong>&nbsp;</span>（请用第3种方法）<br>1、servlet方式加载时，<br>【web.xml】</p>
    <p>Xml代码&nbsp;&nbsp;<a title="收藏这段代码" style="color: rgb(16, 138, 198); text-decoration: underline;"><img class="star" src="http://elf8848.iteye.com/images/icon_star.png" alt="收藏代码"></a></p>
    <ol class="dp-xml list-paddingleft-2" style="font-size: 1em; line-height: 1.4em; margin-bottom: 1px; padding: 2px 0px; border: 1px solid rgb(209, 215, 220); list-style-position: initial; list-style-image: initial; color: rgb(43, 145, 175);">
     <li><p><span style="color: black;"><span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&lt;</span><span class="tag-name" style="color: rgb(0, 102, 153); font-weight: bold;">servlet</span><span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&gt;</span>&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;"><span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&lt;</span><span class="tag-name" style="color: rgb(0, 102, 153); font-weight: bold;">servlet-name</span><span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&gt;</span>springMVC<span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&lt;/</span><span class="tag-name" style="color: rgb(0, 102, 153); font-weight: bold;">servlet-name</span><span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&gt;</span>&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;"><span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&lt;</span><span class="tag-name" style="color: rgb(0, 102, 153); font-weight: bold;">servlet-class</span><span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&gt;</span>org.springframework.web.servlet.DispatcherServlet<span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&lt;/</span><span class="tag-name" style="color: rgb(0, 102, 153); font-weight: bold;">servlet-class</span><span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&gt;</span>&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;"><span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&lt;</span><span class="tag-name" style="color: rgb(0, 102, 153); font-weight: bold;">init-param</span><span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&gt;</span>&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;"><span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&lt;</span><span class="tag-name" style="color: rgb(0, 102, 153); font-weight: bold;">param-name</span><span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&gt;</span>contextConfigLocation<span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&lt;/</span><span class="tag-name" style="color: rgb(0, 102, 153); font-weight: bold;">param-name</span><span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&gt;</span>&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;"><span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&lt;</span><span class="tag-name" style="color: rgb(0, 102, 153); font-weight: bold;">param-value</span><span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&gt;</span>classpath*:/springMVC.xml<span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&lt;/</span><span class="tag-name" style="color: rgb(0, 102, 153); font-weight: bold;">param-value</span><span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&gt;</span>&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;"><span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&lt;/</span><span class="tag-name" style="color: rgb(0, 102, 153); font-weight: bold;">init-param</span><span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&gt;</span>&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;"><span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&lt;</span><span class="tag-name" style="color: rgb(0, 102, 153); font-weight: bold;">load-on-startup</span><span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&gt;</span>1<span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&lt;/</span><span class="tag-name" style="color: rgb(0, 102, 153); font-weight: bold;">load-on-startup</span><span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&gt;</span>&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;"><span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&lt;/</span><span class="tag-name" style="color: rgb(0, 102, 153); font-weight: bold;">servlet</span><span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&gt;</span>&nbsp;&nbsp;</span></p></li>
    </ol>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">&nbsp;spring容器放在ServletContext中的key是org.springframework.web.servlet.FrameworkServlet.CONTEXT.springMVC<br>注意后面的springMVC，是你的servlet-name配置的值，注意适时修改。</p>
    <p>Java代码&nbsp;&nbsp;<a title="收藏这段代码" style="color: rgb(16, 138, 198); text-decoration: underline;"><img class="star" src="http://elf8848.iteye.com/images/icon_star.png" alt="收藏代码"></a></p>
    <ol class="dp-j list-paddingleft-2" style="font-size: 1em; line-height: 1.4em; margin-bottom: 1px; padding: 2px 0px; border: 1px solid rgb(209, 215, 220); list-style-position: initial; list-style-image: initial; color: rgb(43, 145, 175);">
     <li><p><span style="color: black;">ServletContext&nbsp;sc=略&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;">WebApplicationContext&nbsp;attr&nbsp;=&nbsp;(WebApplicationContext)sc.getAttribute(<span class="string" style="color: blue;">"org.springframework.web.servlet.FrameworkServlet.CONTEXT.springMVC"</span>);&nbsp;&nbsp;</span></p></li>
    </ol>
    <p><span style="font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; background-color: rgb(255, 255, 255);">&nbsp;</span></p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">2、listener方式加载时：<br>【web.xml】</p>
    <p>Xml代码&nbsp;&nbsp;<a title="收藏这段代码" style="color: rgb(16, 138, 198); text-decoration: underline;"><img class="star" src="http://elf8848.iteye.com/images/icon_star.png" alt="收藏代码"></a></p>
    <ol class="dp-xml list-paddingleft-2" style="font-size: 1em; line-height: 1.4em; margin-bottom: 1px; padding: 2px 0px; border: 1px solid rgb(209, 215, 220); list-style-position: initial; list-style-image: initial; color: rgb(43, 145, 175);">
     <li><p><span style="color: black;"><span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&lt;</span><span class="tag-name" style="color: rgb(0, 102, 153); font-weight: bold;">context-param</span><span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&gt;</span>&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;">&nbsp;&nbsp;<span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&lt;</span><span class="tag-name" style="color: rgb(0, 102, 153); font-weight: bold;">param-name</span><span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&gt;</span>contextConfigLocation<span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&lt;/</span><span class="tag-name" style="color: rgb(0, 102, 153); font-weight: bold;">param-name</span><span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&gt;</span>&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;">&nbsp;&nbsp;<span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&lt;</span><span class="tag-name" style="color: rgb(0, 102, 153); font-weight: bold;">param-value</span><span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&gt;</span>/WEB-INF/applicationContext<span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&lt;/</span><span class="tag-name" style="color: rgb(0, 102, 153); font-weight: bold;">param-value</span><span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&gt;</span>&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;"><span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&lt;/</span><span class="tag-name" style="color: rgb(0, 102, 153); font-weight: bold;">context-param</span><span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&gt;</span>&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;">&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;"><span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&lt;</span><span class="tag-name" style="color: rgb(0, 102, 153); font-weight: bold;">listener</span><span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&gt;</span>&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;">&nbsp;&nbsp;<span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&lt;</span><span class="tag-name" style="color: rgb(0, 102, 153); font-weight: bold;">listener-class</span><span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&gt;</span>org.springframework.web.context.ContextLoaderListener<span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&lt;/</span><span class="tag-name" style="color: rgb(0, 102, 153); font-weight: bold;">listener-class</span><span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&gt;</span>&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;"><span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&lt;/</span><span class="tag-name" style="color: rgb(0, 102, 153); font-weight: bold;">listener</span><span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&gt;</span>&nbsp;&nbsp;</span></p></li>
    </ol>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">&nbsp;【jsp/servlet】可以这样取得</p>
    <p>Java代码&nbsp;&nbsp;<a title="收藏这段代码" style="color: rgb(16, 138, 198); text-decoration: underline;"><img class="star" src="http://elf8848.iteye.com/images/icon_star.png" alt="收藏代码"></a></p>
    <ol class="dp-j list-paddingleft-2" style="font-size: 1em; line-height: 1.4em; margin-bottom: 1px; padding: 2px 0px; border: 1px solid rgb(209, 215, 220); list-style-position: initial; list-style-image: initial; color: rgb(43, 145, 175);">
     <li><p><span style="color: black;">ServletContext&nbsp;context&nbsp;=&nbsp;getServletContext();&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;">WebApplicationContext&nbsp;applicationContext&nbsp;&nbsp;=&nbsp;WebApplicationContextUtils&nbsp;.getWebApplicationContext(context);&nbsp;&nbsp;&nbsp;</span></p></li>
    </ol>
    <p><span style="font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; background-color: rgb(255, 255, 255);">&nbsp;</span></p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">3、通用的方法来了，神器啊，前的&nbsp; 1、2两种方法并不通用，可以抛弃了。<br>在配置文件中加入：</p>
    <p>Xml代码&nbsp;&nbsp;<a title="收藏这段代码" style="color: rgb(16, 138, 198); text-decoration: underline;"><img class="star" src="http://elf8848.iteye.com/images/icon_star.png" alt="收藏代码"></a></p>
    <ol class="dp-xml list-paddingleft-2" style="font-size: 1em; line-height: 1.4em; margin-bottom: 1px; padding: 2px 0px; border: 1px solid rgb(209, 215, 220); list-style-position: initial; list-style-image: initial; color: rgb(43, 145, 175);">
     <li><p><span style="color: black;"><span class="comments" style="color: rgb(0, 130, 0); padding: 0px; margin: 0px; width: auto; border: 0px;">&lt;!--&nbsp;用于持有ApplicationContext,可以使用SpringContextHolder.getBean('xxxx')的静态方法得到spring&nbsp;bean对象&nbsp;--&gt;</span>&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;"><span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&lt;</span><span class="tag-name" style="color: rgb(0, 102, 153); font-weight: bold;">bean</span>&nbsp;<span class="attribute" style="color: red;">class</span>=<span class="attribute-value" style="color: blue;">"com.xxxxx.SpringContextHolder"</span>&nbsp;<span class="attribute" style="color: red;">lazy-init</span>=<span class="attribute-value" style="color: blue;">"false"</span>&nbsp;<span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">/&gt;</span>&nbsp;&nbsp;</span></p></li>
    </ol>
    <p><span style="font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; background-color: rgb(255, 255, 255);">&nbsp;</span></p>
    <p>Java代码&nbsp;&nbsp;<a title="收藏这段代码" style="color: rgb(16, 138, 198); text-decoration: underline;"><img class="star" src="http://elf8848.iteye.com/images/icon_star.png" alt="收藏代码"></a></p>
    <ol class="dp-j list-paddingleft-2" style="font-size: 1em; line-height: 1.4em; margin-bottom: 1px; padding: 2px 0px; border: 1px solid rgb(209, 215, 220); list-style-position: initial; list-style-image: initial; color: rgb(43, 145, 175);">
     <li><p><span style="color: black;"><span class="keyword" style="color: rgb(127, 0, 85); font-weight: bold;">import</span>&nbsp;org.springframework.context.ApplicationContext;&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;"><span class="keyword" style="color: rgb(127, 0, 85); font-weight: bold;">import</span>&nbsp;org.springframework.context.ApplicationContextAware;&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;"><span class="comment" style="color: rgb(0, 130, 0); padding: 0px; margin: 0px; width: auto; border: 0px;">/**</span>&nbsp;</span></p></li>
     <li><p><span style="color: black;"><span class="comment" style="color: rgb(0, 130, 0); padding: 0px; margin: 0px; width: auto; border: 0px;">&nbsp;*&nbsp;以静态变量保存Spring&nbsp;ApplicationContext,&nbsp;可在任何代码任何地方任何时候中取出ApplicaitonContext.</span>&nbsp;</span></p></li>
     <li><p><span style="color: black;"><span class="comment" style="color: rgb(0, 130, 0); padding: 0px; margin: 0px; width: auto; border: 0px;">&nbsp;*&nbsp;</span>&nbsp;</span></p></li>
     <li><p><span style="color: black;"><span class="comment" style="color: rgb(0, 130, 0); padding: 0px; margin: 0px; width: auto; border: 0px;">&nbsp;*/</span>&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;"><span class="keyword" style="color: rgb(127, 0, 85); font-weight: bold;">public</span>&nbsp;<span class="keyword" style="color: rgb(127, 0, 85); font-weight: bold;">class</span>&nbsp;SpringContextHolder&nbsp;<span class="keyword" style="color: rgb(127, 0, 85); font-weight: bold;">implements</span>&nbsp;ApplicationContextAware&nbsp;{&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;"><span class="keyword" style="color: rgb(127, 0, 85); font-weight: bold;">private</span>&nbsp;<span class="keyword" style="color: rgb(127, 0, 85); font-weight: bold;">static</span>&nbsp;ApplicationContext&nbsp;applicationContext;&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;">&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;"><span class="comment" style="color: rgb(0, 130, 0); padding: 0px; margin: 0px; width: auto; border: 0px;">/**</span>&nbsp;</span></p></li>
     <li><p><span style="color: black;"><span class="comment" style="color: rgb(0, 130, 0); padding: 0px; margin: 0px; width: auto; border: 0px;">*&nbsp;实现ApplicationContextAware接口的context注入函数,&nbsp;将其存入静态变量.</span>&nbsp;</span></p></li>
     <li><p><span style="color: black;"><span class="comment" style="color: rgb(0, 130, 0); padding: 0px; margin: 0px; width: auto; border: 0px;">*/</span>&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;"><span class="keyword" style="color: rgb(127, 0, 85); font-weight: bold;">public</span>&nbsp;<span class="keyword" style="color: rgb(127, 0, 85); font-weight: bold;">void</span>&nbsp;setApplicationContext(ApplicationContext&nbsp;applicationContext)&nbsp;{&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;">SpringContextHolder.applicationContext&nbsp;=&nbsp;applicationContext;&nbsp;<span class="comment" style="color: rgb(0, 130, 0); padding: 0px; margin: 0px; width: auto; border: 0px;">//&nbsp;NOSONAR</span>&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;">}&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;">&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;"><span class="comment" style="color: rgb(0, 130, 0); padding: 0px; margin: 0px; width: auto; border: 0px;">/**</span>&nbsp;</span></p></li>
     <li><p><span style="color: black;"><span class="comment" style="color: rgb(0, 130, 0); padding: 0px; margin: 0px; width: auto; border: 0px;">*&nbsp;取得存储在静态变量中的ApplicationContext.</span>&nbsp;</span></p></li>
     <li><p><span style="color: black;"><span class="comment" style="color: rgb(0, 130, 0); padding: 0px; margin: 0px; width: auto; border: 0px;">*/</span>&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;"><span class="keyword" style="color: rgb(127, 0, 85); font-weight: bold;">public</span>&nbsp;<span class="keyword" style="color: rgb(127, 0, 85); font-weight: bold;">static</span>&nbsp;ApplicationContext&nbsp;getApplicationContext()&nbsp;{&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;">checkApplicationContext();&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;"><span class="keyword" style="color: rgb(127, 0, 85); font-weight: bold;">return</span>&nbsp;applicationContext;&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;">}&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;">&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;"><span class="comment" style="color: rgb(0, 130, 0); padding: 0px; margin: 0px; width: auto; border: 0px;">/**</span>&nbsp;</span></p></li>
     <li><p><span style="color: black;"><span class="comment" style="color: rgb(0, 130, 0); padding: 0px; margin: 0px; width: auto; border: 0px;">*&nbsp;从静态变量ApplicationContext中取得Bean,&nbsp;自动转型为所赋值对象的类型.</span>&nbsp;</span></p></li>
     <li><p><span style="color: black;"><span class="comment" style="color: rgb(0, 130, 0); padding: 0px; margin: 0px; width: auto; border: 0px;">*/</span>&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;"><span class="annotation" style="color: rgb(100, 100, 100);">@SuppressWarnings</span>(<span class="string" style="color: blue;">"unchecked"</span>)&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;"><span class="keyword" style="color: rgb(127, 0, 85); font-weight: bold;">public</span>&nbsp;<span class="keyword" style="color: rgb(127, 0, 85); font-weight: bold;">static</span>&nbsp;&lt;T&gt;&nbsp;T&nbsp;getBean(String&nbsp;name)&nbsp;{&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;">checkApplicationContext();&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;"><span class="keyword" style="color: rgb(127, 0, 85); font-weight: bold;">return</span>&nbsp;(T)&nbsp;applicationContext.getBean(name);&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;">}&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;">&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;"><span class="comment" style="color: rgb(0, 130, 0); padding: 0px; margin: 0px; width: auto; border: 0px;">/**</span>&nbsp;</span></p></li>
     <li><p><span style="color: black;"><span class="comment" style="color: rgb(0, 130, 0); padding: 0px; margin: 0px; width: auto; border: 0px;">*&nbsp;从静态变量ApplicationContext中取得Bean,&nbsp;自动转型为所赋值对象的类型.</span>&nbsp;</span></p></li>
     <li><p><span style="color: black;"><span class="comment" style="color: rgb(0, 130, 0); padding: 0px; margin: 0px; width: auto; border: 0px;">*/</span>&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;"><span class="annotation" style="color: rgb(100, 100, 100);">@SuppressWarnings</span>(<span class="string" style="color: blue;">"unchecked"</span>)&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;"><span class="keyword" style="color: rgb(127, 0, 85); font-weight: bold;">public</span>&nbsp;<span class="keyword" style="color: rgb(127, 0, 85); font-weight: bold;">static</span>&nbsp;&lt;T&gt;&nbsp;T&nbsp;getBean(Class&lt;T&gt;&nbsp;clazz)&nbsp;{&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;">checkApplicationContext();&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;"><span class="keyword" style="color: rgb(127, 0, 85); font-weight: bold;">return</span>&nbsp;(T)&nbsp;applicationContext.getBeansOfType(clazz);&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;">}&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;">&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;"><span class="comment" style="color: rgb(0, 130, 0); padding: 0px; margin: 0px; width: auto; border: 0px;">/**</span>&nbsp;</span></p></li>
     <li><p><span style="color: black;"><span class="comment" style="color: rgb(0, 130, 0); padding: 0px; margin: 0px; width: auto; border: 0px;">*&nbsp;清除applicationContext静态变量.</span>&nbsp;</span></p></li>
     <li><p><span style="color: black;"><span class="comment" style="color: rgb(0, 130, 0); padding: 0px; margin: 0px; width: auto; border: 0px;">*/</span>&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;"><span class="keyword" style="color: rgb(127, 0, 85); font-weight: bold;">public</span>&nbsp;<span class="keyword" style="color: rgb(127, 0, 85); font-weight: bold;">static</span>&nbsp;<span class="keyword" style="color: rgb(127, 0, 85); font-weight: bold;">void</span>&nbsp;cleanApplicationContext()&nbsp;{&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;">applicationContext&nbsp;=&nbsp;<span class="keyword" style="color: rgb(127, 0, 85); font-weight: bold;">null</span>;&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;">}&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;">&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;"><span class="keyword" style="color: rgb(127, 0, 85); font-weight: bold;">private</span>&nbsp;<span class="keyword" style="color: rgb(127, 0, 85); font-weight: bold;">static</span>&nbsp;<span class="keyword" style="color: rgb(127, 0, 85); font-weight: bold;">void</span>&nbsp;checkApplicationContext()&nbsp;{&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;"><span class="keyword" style="color: rgb(127, 0, 85); font-weight: bold;">if</span>&nbsp;(applicationContext&nbsp;==&nbsp;<span class="keyword" style="color: rgb(127, 0, 85); font-weight: bold;">null</span>)&nbsp;{&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;"><span class="keyword" style="color: rgb(127, 0, 85); font-weight: bold;">throw</span>&nbsp;<span class="keyword" style="color: rgb(127, 0, 85); font-weight: bold;">new</span>&nbsp;IllegalStateException(<span class="string" style="color: blue;">"applicaitonContext未注入,请在applicationContext.xml中定义SpringContextHolder"</span>);&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;">}&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;">}&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;">}&nbsp;&nbsp;</span></p></li>
    </ol>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">&nbsp;&nbsp;转载请注明出处：原文地址：<a href="http://elf8848.iteye.com/blog/875830" style="color: rgb(16, 138, 198);">http://elf8848.iteye.com/blog/875830</a></p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">&nbsp;</p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">&nbsp;</p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);"><span style="font-size: medium;"><strong>十八、多视图控制器</strong></span></p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">&nbsp;</p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">当有jsp,flt (模板)等多种页面生成展示方式时，spring默认使用的是“视图解析器链”。 真是一个链，所以性能不好，spring会在“视图解析器链”中顺序的查找，直到找到对应的 “视图解析器” 。jsp视图解析器一定要写在最后面，因为一旦调用jsp，就向浏览器发出数据了，Spring就没有机会再尝试下一个了。</p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">所以自己写一个"多视图解析器"，依靠扩展名来区分，可一次准确的选中一个 视图解析器,提高性能（会有多少提高呢？没测试过）.</p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">&nbsp;</p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">下面的例子支持jsp,flt (模板)两种页面生成展示方式，你中以自己添加，支持更多。</p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">&nbsp;</p>
    <p>Xml代码&nbsp;&nbsp;<a title="收藏这段代码" style="color: rgb(16, 138, 198); text-decoration: underline;"><img class="star" src="http://elf8848.iteye.com/images/icon_star.png" alt="收藏代码"></a></p>
    <ol class="dp-xml list-paddingleft-2" style="font-size: 1em; line-height: 1.4em; margin-bottom: 1px; padding: 2px 0px; border: 1px solid rgb(209, 215, 220); list-style-position: initial; list-style-image: initial; color: rgb(43, 145, 175);">
     <li><p><span style="color: black;">&nbsp;&nbsp;&nbsp;<span class="comments" style="color: rgb(0, 130, 0); padding: 0px; margin: 0px; width: auto; border: 0px;">&lt;!--&nbsp;多视图处理器&nbsp;--&gt;</span>&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;">&nbsp;&nbsp;&nbsp;<span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&lt;</span><span class="tag-name" style="color: rgb(0, 102, 153); font-weight: bold;">bean</span>&nbsp;<span class="attribute" style="color: red;">class</span>=<span class="attribute-value" style="color: blue;">"com.xxx.core.web.MixedViewResolver"</span><span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&gt;</span>&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;">&nbsp;&nbsp;&nbsp;&nbsp;<span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&lt;</span><span class="tag-name" style="color: rgb(0, 102, 153); font-weight: bold;">property</span>&nbsp;<span class="attribute" style="color: red;">name</span>=<span class="attribute-value" style="color: blue;">"resolvers"</span><span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&gt;</span>&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&lt;</span><span class="tag-name" style="color: rgb(0, 102, 153); font-weight: bold;">map</span><span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&gt;</span>&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&lt;</span><span class="tag-name" style="color: rgb(0, 102, 153); font-weight: bold;">entry</span>&nbsp;<span class="attribute" style="color: red;">key</span>=<span class="attribute-value" style="color: blue;">"jsp"</span><span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&gt;</span>&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&lt;</span><span class="tag-name" style="color: rgb(0, 102, 153); font-weight: bold;">bean</span>&nbsp;<span class="attribute" style="color: red;">class</span>=<span class="attribute-value" style="color: blue;">"org.springframework.web.servlet.view.InternalResourceViewResolver"</span><span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&gt;</span>&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&lt;</span><span class="tag-name" style="color: rgb(0, 102, 153); font-weight: bold;">property</span>&nbsp;<span class="attribute" style="color: red;">name</span>=<span class="attribute-value" style="color: blue;">"prefix"</span>&nbsp;<span class="attribute" style="color: red;">value</span>=<span class="attribute-value" style="color: blue;">"/WEB-INF/jsp/"</span><span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">/&gt;</span>&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&lt;</span><span class="tag-name" style="color: rgb(0, 102, 153); font-weight: bold;">property</span>&nbsp;<span class="attribute" style="color: red;">name</span>=<span class="attribute-value" style="color: blue;">"viewClass"</span>&nbsp;<span class="attribute" style="color: red;">value</span>=<span class="attribute-value" style="color: blue;">"org.springframework.web.servlet.view.JstlView"</span><span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&gt;</span><span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&lt;/</span><span class="tag-name" style="color: rgb(0, 102, 153); font-weight: bold;">property</span><span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&gt;</span>&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&lt;/</span><span class="tag-name" style="color: rgb(0, 102, 153); font-weight: bold;">bean</span><span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&gt;</span>&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&lt;/</span><span class="tag-name" style="color: rgb(0, 102, 153); font-weight: bold;">entry</span><span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&gt;</span>&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&lt;</span><span class="tag-name" style="color: rgb(0, 102, 153); font-weight: bold;">entry</span>&nbsp;<span class="attribute" style="color: red;">key</span>=<span class="attribute-value" style="color: blue;">"ftl"</span><span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&gt;</span>&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&lt;</span><span class="tag-name" style="color: rgb(0, 102, 153); font-weight: bold;">bean</span>&nbsp;<span class="attribute" style="color: red;">class</span>=<span class="attribute-value" style="color: blue;">"org.springframework.web.servlet.view.freemarker.FreeMarkerViewResolver"</span><span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&gt;</span>&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&lt;</span><span class="tag-name" style="color: rgb(0, 102, 153); font-weight: bold;">property</span>&nbsp;<span class="attribute" style="color: red;">name</span>=<span class="attribute-value" style="color: blue;">"cache"</span>&nbsp;<span class="attribute" style="color: red;">value</span>=<span class="attribute-value" style="color: blue;">"true"</span><span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">/&gt;</span>&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&lt;</span><span class="tag-name" style="color: rgb(0, 102, 153); font-weight: bold;">property</span>&nbsp;<span class="attribute" style="color: red;">name</span>=<span class="attribute-value" style="color: blue;">"contentType"</span>&nbsp;<span class="attribute" style="color: red;">value</span>=<span class="attribute-value" style="color: blue;">"text/html;charset=UTF-8"</span><span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&gt;</span><span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&lt;/</span><span class="tag-name" style="color: rgb(0, 102, 153); font-weight: bold;">property</span><span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&gt;</span>&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="comments" style="color: rgb(0, 130, 0); padding: 0px; margin: 0px; width: auto; border: 0px;">&lt;!--&nbsp;宏命令的支持&nbsp;&nbsp;--&gt;</span>&nbsp;&nbsp;&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&lt;</span><span class="tag-name" style="color: rgb(0, 102, 153); font-weight: bold;">property</span>&nbsp;<span class="attribute" style="color: red;">name</span>=<span class="attribute-value" style="color: blue;">"exposeSpringMacroHelpers"</span>&nbsp;<span class="attribute" style="color: red;">value</span>=<span class="attribute-value" style="color: blue;">"true"</span><span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">/&gt;</span>&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&lt;</span><span class="tag-name" style="color: rgb(0, 102, 153); font-weight: bold;">property</span>&nbsp;<span class="attribute" style="color: red;">name</span>=<span class="attribute-value" style="color: blue;">"viewClass"</span>&nbsp;<span class="attribute" style="color: red;">value</span>=<span class="attribute-value" style="color: blue;">"org.springframework.web.servlet.view.freemarker.FreeMarkerView"</span><span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">/&gt;</span>&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&lt;</span><span class="tag-name" style="color: rgb(0, 102, 153); font-weight: bold;">property</span>&nbsp;<span class="attribute" style="color: red;">name</span>=<span class="attribute-value" style="color: blue;">"requestContextAttribute"</span>&nbsp;<span class="attribute" style="color: red;">value</span>=<span class="attribute-value" style="color: blue;">"rc"</span><span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&gt;</span><span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&lt;/</span><span class="tag-name" style="color: rgb(0, 102, 153); font-weight: bold;">property</span><span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&gt;</span>&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&lt;/</span><span class="tag-name" style="color: rgb(0, 102, 153); font-weight: bold;">bean</span><span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&gt;</span>&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&lt;/</span><span class="tag-name" style="color: rgb(0, 102, 153); font-weight: bold;">entry</span><span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&gt;</span>&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&lt;/</span><span class="tag-name" style="color: rgb(0, 102, 153); font-weight: bold;">map</span><span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&gt;</span>&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;">&nbsp;&nbsp;&nbsp;&nbsp;<span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&lt;/</span><span class="tag-name" style="color: rgb(0, 102, 153); font-weight: bold;">property</span><span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&gt;</span>&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;"><span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&lt;/</span><span class="tag-name" style="color: rgb(0, 102, 153); font-weight: bold;">bean</span><span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&gt;</span>&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;">&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;"><span class="comments" style="color: rgb(0, 130, 0); padding: 0px; margin: 0px; width: auto; border: 0px;">&lt;!--&nbsp;freemarker&nbsp;config&nbsp;--&gt;</span>&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;">&nbsp;&nbsp;&nbsp;<span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&lt;</span><span class="tag-name" style="color: rgb(0, 102, 153); font-weight: bold;">bean</span>&nbsp;<span class="attribute" style="color: red;">id</span>=<span class="attribute-value" style="color: blue;">"freeMarkerConfigurer"</span>&nbsp;<span class="attribute" style="color: red;">class</span>=<span class="attribute-value" style="color: blue;">"org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer"</span><span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&gt;</span>&nbsp;&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&lt;</span><span class="tag-name" style="color: rgb(0, 102, 153); font-weight: bold;">property</span>&nbsp;<span class="attribute" style="color: red;">name</span>=<span class="attribute-value" style="color: blue;">"templateLoaderPath"</span>&nbsp;<span class="attribute" style="color: red;">value</span>=<span class="attribute-value" style="color: blue;">"/WEB-INF/ftl/"</span>&nbsp;<span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">/&gt;</span>&nbsp;&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&lt;</span><span class="tag-name" style="color: rgb(0, 102, 153); font-weight: bold;">property</span>&nbsp;<span class="attribute" style="color: red;">name</span>=<span class="attribute-value" style="color: blue;">"freemarkerSettings"</span><span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&gt;</span>&nbsp;&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&lt;</span><span class="tag-name" style="color: rgb(0, 102, 153); font-weight: bold;">props</span><span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&gt;</span>&nbsp;&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&lt;</span><span class="tag-name" style="color: rgb(0, 102, 153); font-weight: bold;">prop</span>&nbsp;<span class="attribute" style="color: red;">key</span>=<span class="attribute-value" style="color: blue;">"template_update_delay"</span><span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&gt;</span>5<span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&lt;/</span><span class="tag-name" style="color: rgb(0, 102, 153); font-weight: bold;">prop</span><span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&gt;</span>&nbsp;&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&lt;</span><span class="tag-name" style="color: rgb(0, 102, 153); font-weight: bold;">prop</span>&nbsp;<span class="attribute" style="color: red;">key</span>=<span class="attribute-value" style="color: blue;">"default_encoding"</span><span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&gt;</span>UTF-8<span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&lt;/</span><span class="tag-name" style="color: rgb(0, 102, 153); font-weight: bold;">prop</span><span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&gt;</span>&nbsp;&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&lt;</span><span class="tag-name" style="color: rgb(0, 102, 153); font-weight: bold;">prop</span>&nbsp;<span class="attribute" style="color: red;">key</span>=<span class="attribute-value" style="color: blue;">"locale"</span><span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&gt;</span>zh_CN<span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&lt;/</span><span class="tag-name" style="color: rgb(0, 102, 153); font-weight: bold;">prop</span><span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&gt;</span>&nbsp;&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&lt;/</span><span class="tag-name" style="color: rgb(0, 102, 153); font-weight: bold;">props</span><span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&gt;</span>&nbsp;&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&lt;/</span><span class="tag-name" style="color: rgb(0, 102, 153); font-weight: bold;">property</span><span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&gt;</span>&nbsp;&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;">&nbsp;&nbsp;&nbsp;<span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&lt;/</span><span class="tag-name" style="color: rgb(0, 102, 153); font-weight: bold;">bean</span><span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&gt;</span>&nbsp;&nbsp;&nbsp;</span></p></li>
    </ol>
    <p><span style="font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; background-color: rgb(255, 255, 255);">&nbsp;&nbsp;</span></p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">&nbsp;</p>
    <p>Java代码&nbsp;&nbsp;<a title="收藏这段代码" style="color: rgb(16, 138, 198); text-decoration: underline;"><img class="star" src="http://elf8848.iteye.com/images/icon_star.png" alt="收藏代码"></a></p>
    <ol class="dp-j list-paddingleft-2" style="font-size: 1em; line-height: 1.4em; margin-bottom: 1px; padding: 2px 0px; border: 1px solid rgb(209, 215, 220); list-style-position: initial; list-style-image: initial; color: rgb(43, 145, 175);">
     <li><p><span style="color: black;"><span class="keyword" style="color: rgb(127, 0, 85); font-weight: bold;">import</span>&nbsp;java.util.Locale;&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;"><span class="keyword" style="color: rgb(127, 0, 85); font-weight: bold;">import</span>&nbsp;java.util.Map;&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;"><span class="keyword" style="color: rgb(127, 0, 85); font-weight: bold;">import</span>&nbsp;org.springframework.web.servlet.View;&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;"><span class="keyword" style="color: rgb(127, 0, 85); font-weight: bold;">import</span>&nbsp;org.springframework.web.servlet.ViewResolver;&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;">&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;"><span class="comment" style="color: rgb(0, 130, 0); padding: 0px; margin: 0px; width: auto; border: 0px;">/**&nbsp;</span>&nbsp;</span></p></li>
     <li><p><span style="color: black;"><span class="comment" style="color: rgb(0, 130, 0); padding: 0px; margin: 0px; width: auto; border: 0px;">*&nbsp;说明：&nbsp;多视图处理器</span>&nbsp;</span></p></li>
     <li><p><span style="color: black;"><span class="comment" style="color: rgb(0, 130, 0); padding: 0px; margin: 0px; width: auto; border: 0px;">*&nbsp;</span>&nbsp;</span></p></li>
     <li><p><span style="color: black;"><span class="comment" style="color: rgb(0, 130, 0); padding: 0px; margin: 0px; width: auto; border: 0px;">*&nbsp;@author&nbsp;&nbsp;赵磊&nbsp;</span>&nbsp;</span></p></li>
     <li><p><span style="color: black;"><span class="comment" style="color: rgb(0, 130, 0); padding: 0px; margin: 0px; width: auto; border: 0px;">*&nbsp;@version&nbsp;创建时间：2011-8-19&nbsp;上午09:41:09&nbsp;&nbsp;</span>&nbsp;</span></p></li>
     <li><p><span style="color: black;"><span class="comment" style="color: rgb(0, 130, 0); padding: 0px; margin: 0px; width: auto; border: 0px;">*/</span>&nbsp;&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;"><span class="keyword" style="color: rgb(127, 0, 85); font-weight: bold;">public</span>&nbsp;<span class="keyword" style="color: rgb(127, 0, 85); font-weight: bold;">class</span>&nbsp;MixedViewResolver&nbsp;<span class="keyword" style="color: rgb(127, 0, 85); font-weight: bold;">implements</span>&nbsp;ViewResolver{&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;">&nbsp;&nbsp;&nbsp;&nbsp;<span class="keyword" style="color: rgb(127, 0, 85); font-weight: bold;">private</span>&nbsp;Map&lt;String,ViewResolver&gt;&nbsp;resolvers;&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;">&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;">&nbsp;&nbsp;&nbsp;&nbsp;<span class="keyword" style="color: rgb(127, 0, 85); font-weight: bold;">public</span>&nbsp;<span class="keyword" style="color: rgb(127, 0, 85); font-weight: bold;">void</span>&nbsp;setResolvers(Map&lt;String,&nbsp;ViewResolver&gt;&nbsp;resolvers)&nbsp;{&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="keyword" style="color: rgb(127, 0, 85); font-weight: bold;">this</span>.resolvers&nbsp;=&nbsp;resolvers;&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;">&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;">&nbsp;&nbsp;&nbsp;&nbsp;<span class="keyword" style="color: rgb(127, 0, 85); font-weight: bold;">public</span>&nbsp;View&nbsp;resolveViewName(String&nbsp;viewName,Locale&nbsp;locale)&nbsp;<span class="keyword" style="color: rgb(127, 0, 85); font-weight: bold;">throws</span>&nbsp;Exception{&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="keyword" style="color: rgb(127, 0, 85); font-weight: bold;">int</span>&nbsp;n=viewName.lastIndexOf(<span class="string" style="color: blue;">"."</span>);&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="keyword" style="color: rgb(127, 0, 85); font-weight: bold;">if</span>(n!=-<span class="number" style="color: rgb(192, 0, 0);">1</span>){&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="comment" style="color: rgb(0, 130, 0); padding: 0px; margin: 0px; width: auto; border: 0px;">//取出扩展名</span>&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;String&nbsp;suffix=viewName.substring(n+<span class="number" style="color: rgb(192, 0, 0);">1</span>);&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="comment" style="color: rgb(0, 130, 0); padding: 0px; margin: 0px; width: auto; border: 0px;">//取出对应的ViewResolver</span>&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ViewResolver&nbsp;resolver=resolvers.get(suffix);&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="keyword" style="color: rgb(127, 0, 85); font-weight: bold;">if</span>(resolver==<span class="keyword" style="color: rgb(127, 0, 85); font-weight: bold;">null</span>){&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="keyword" style="color: rgb(127, 0, 85); font-weight: bold;">throw</span>&nbsp;<span class="keyword" style="color: rgb(127, 0, 85); font-weight: bold;">new</span>&nbsp;RuntimeException(<span class="string" style="color: blue;">"No&nbsp;ViewResolver&nbsp;for&nbsp;"</span>+suffix);&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="keyword" style="color: rgb(127, 0, 85); font-weight: bold;">return</span>&nbsp;&nbsp;resolver.resolveViewName(viewName,&nbsp;locale);&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<span class="keyword" style="color: rgb(127, 0, 85); font-weight: bold;">else</span>{&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ViewResolver&nbsp;resolver=resolvers.get(<span class="string" style="color: blue;">"jsp"</span>);&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="keyword" style="color: rgb(127, 0, 85); font-weight: bold;">return</span>&nbsp;&nbsp;resolver.resolveViewName(viewName,&nbsp;locale);&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;">&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;">}&nbsp;&nbsp;</span></p></li>
    </ol>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">&nbsp;&nbsp;转载请注明出处：原文地址：<a href="http://elf8848.iteye.com/blog/875830" style="color: rgb(16, 138, 198);">http://elf8848.iteye.com/blog/875830</a></p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">&nbsp;</p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">&nbsp;</p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);"><strong><span style="font-size: medium;">十九、&nbsp;</span><span style="font-size: medium;">&lt;mvc:annotation-driven /&gt;&nbsp;</span><span style="font-size: medium;">到底做了什么工作</span></strong></p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">&nbsp;</p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">&nbsp;</p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);"><span style="font-size: small;">一句</span>&nbsp;<span style="font-size: small;">&lt;mvc:annotation-driven /&gt;实际做了以下工作：（不包括添加自己定义的拦截器）</span></p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);"><span style="font-size: small;">我们了解这些之后，对Spring3 MVC的控制力就更强大了，想改哪就改哪里。</span></p>
    <p>Xml代码&nbsp;&nbsp;<a title="收藏这段代码" style="color: rgb(16, 138, 198); text-decoration: underline;"><img class="star" src="http://elf8848.iteye.com/images/icon_star.png" alt="收藏代码"></a></p>
    <ol class="dp-xml list-paddingleft-2" style="font-size: 1em; line-height: 1.4em; margin-bottom: 1px; padding: 2px 0px; border: 1px solid rgb(209, 215, 220); list-style-position: initial; list-style-image: initial; color: rgb(43, 145, 175);">
     <li><p><span style="color: black;">&nbsp;&nbsp;&nbsp;<span class="comments" style="color: rgb(0, 130, 0); padding: 0px; margin: 0px; width: auto; border: 0px;">&lt;!--&nbsp;注解请求映射&nbsp;&nbsp;--&gt;</span>&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;">&nbsp;&nbsp;&nbsp;<span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&lt;</span><span class="tag-name" style="color: rgb(0, 102, 153); font-weight: bold;">bean</span>&nbsp;<span class="attribute" style="color: red;">class</span>=<span class="attribute-value" style="color: blue;">"org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping"</span><span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&gt;</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;">&nbsp;&nbsp;&nbsp;&nbsp;<span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&lt;</span><span class="tag-name" style="color: rgb(0, 102, 153); font-weight: bold;">property</span>&nbsp;<span class="attribute" style="color: red;">name</span>=<span class="attribute-value" style="color: blue;">"interceptors"</span><span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&gt;</span>&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&lt;</span><span class="tag-name" style="color: rgb(0, 102, 153); font-weight: bold;">list</span><span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&gt;</span>&nbsp;&nbsp;&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&lt;</span><span class="tag-name" style="color: rgb(0, 102, 153); font-weight: bold;">ref</span>&nbsp;<span class="attribute" style="color: red;">bean</span>=<span class="attribute-value" style="color: blue;">"logNDCInteceptor"</span><span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">/&gt;</span>&nbsp;&nbsp;&nbsp;<span class="comments" style="color: rgb(0, 130, 0); padding: 0px; margin: 0px; width: auto; border: 0px;">&lt;!--&nbsp;日志拦截器，这是你自定义的拦截器&nbsp;--&gt;</span>&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&lt;</span><span class="tag-name" style="color: rgb(0, 102, 153); font-weight: bold;">ref</span>&nbsp;<span class="attribute" style="color: red;">bean</span>=<span class="attribute-value" style="color: blue;">"myRequestHelperInteceptor"</span><span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">/&gt;</span>&nbsp;&nbsp;&nbsp;<span class="comments" style="color: rgb(0, 130, 0); padding: 0px; margin: 0px; width: auto; border: 0px;">&lt;!--&nbsp;RequestHelper拦截器，这是你自定义的拦截器--&gt;</span>&nbsp;&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&lt;</span><span class="tag-name" style="color: rgb(0, 102, 153); font-weight: bold;">ref</span>&nbsp;<span class="attribute" style="color: red;">bean</span>=<span class="attribute-value" style="color: blue;">"myPermissionsInteceptor"</span><span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">/&gt;</span>&nbsp;&nbsp;<span class="comments" style="color: rgb(0, 130, 0); padding: 0px; margin: 0px; width: auto; border: 0px;">&lt;!--&nbsp;权限拦截器，这是你自定义的拦截器--&gt;</span>&nbsp;&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&lt;</span><span class="tag-name" style="color: rgb(0, 102, 153); font-weight: bold;">ref</span>&nbsp;<span class="attribute" style="color: red;">bean</span>=<span class="attribute-value" style="color: blue;">"myUserInfoInteceptor"</span><span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">/&gt;</span>&nbsp;&nbsp;<span class="comments" style="color: rgb(0, 130, 0); padding: 0px; margin: 0px; width: auto; border: 0px;">&lt;!--&nbsp;用户信息拦截器，这是你自定义的拦截器--&gt;</span>&nbsp;&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&lt;/</span><span class="tag-name" style="color: rgb(0, 102, 153); font-weight: bold;">list</span><span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&gt;</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;">&nbsp;&nbsp;&nbsp;&nbsp;<span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&lt;/</span><span class="tag-name" style="color: rgb(0, 102, 153); font-weight: bold;">property</span><span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&gt;</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;"><span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&lt;/</span><span class="tag-name" style="color: rgb(0, 102, 153); font-weight: bold;">bean</span><span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&gt;</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;"><span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&lt;</span><span class="tag-name" style="color: rgb(0, 102, 153); font-weight: bold;">bean</span>&nbsp;<span class="attribute" style="color: red;">class</span>=<span class="attribute-value" style="color: blue;">"org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter"</span><span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&gt;</span>&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;">&nbsp;&nbsp;&nbsp;&nbsp;<span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&lt;</span><span class="tag-name" style="color: rgb(0, 102, 153); font-weight: bold;">property</span>&nbsp;<span class="attribute" style="color: red;">name</span>=<span class="attribute-value" style="color: blue;">"messageConverters"</span><span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&gt;</span>&nbsp;&nbsp;&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&lt;</span><span class="tag-name" style="color: rgb(0, 102, 153); font-weight: bold;">list</span><span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&gt;</span>&nbsp;&nbsp;&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&lt;</span><span class="tag-name" style="color: rgb(0, 102, 153); font-weight: bold;">ref</span>&nbsp;<span class="attribute" style="color: red;">bean</span>=<span class="attribute-value" style="color: blue;">"byteArray_hmc"</span>&nbsp;<span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">/&gt;</span>&nbsp;&nbsp;&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&lt;</span><span class="tag-name" style="color: rgb(0, 102, 153); font-weight: bold;">ref</span>&nbsp;<span class="attribute" style="color: red;">bean</span>=<span class="attribute-value" style="color: blue;">"string_hmc"</span>&nbsp;<span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">/&gt;</span>&nbsp;&nbsp;&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&lt;</span><span class="tag-name" style="color: rgb(0, 102, 153); font-weight: bold;">ref</span>&nbsp;<span class="attribute" style="color: red;">bean</span>=<span class="attribute-value" style="color: blue;">"resource_hmc"</span>&nbsp;<span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">/&gt;</span>&nbsp;&nbsp;&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&lt;</span><span class="tag-name" style="color: rgb(0, 102, 153); font-weight: bold;">ref</span>&nbsp;<span class="attribute" style="color: red;">bean</span>=<span class="attribute-value" style="color: blue;">"source_hmc"</span>&nbsp;<span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">/&gt;</span>&nbsp;&nbsp;&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&lt;</span><span class="tag-name" style="color: rgb(0, 102, 153); font-weight: bold;">ref</span>&nbsp;<span class="attribute" style="color: red;">bean</span>=<span class="attribute-value" style="color: blue;">"xmlAwareForm_hmc"</span>&nbsp;<span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">/&gt;</span>&nbsp;&nbsp;&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&lt;</span><span class="tag-name" style="color: rgb(0, 102, 153); font-weight: bold;">ref</span>&nbsp;<span class="attribute" style="color: red;">bean</span>=<span class="attribute-value" style="color: blue;">"jaxb2RootElement_hmc"</span>&nbsp;<span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">/&gt;</span>&nbsp;&nbsp;&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&lt;</span><span class="tag-name" style="color: rgb(0, 102, 153); font-weight: bold;">ref</span>&nbsp;<span class="attribute" style="color: red;">bean</span>=<span class="attribute-value" style="color: blue;">"jackson_hmc"</span>&nbsp;<span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">/&gt;</span>&nbsp;&nbsp;&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&lt;/</span><span class="tag-name" style="color: rgb(0, 102, 153); font-weight: bold;">list</span><span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&gt;</span>&nbsp;&nbsp;&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;">&nbsp;&nbsp;&nbsp;&nbsp;<span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&lt;/</span><span class="tag-name" style="color: rgb(0, 102, 153); font-weight: bold;">property</span><span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&gt;</span>&nbsp;&nbsp;&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;"><span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&lt;/</span><span class="tag-name" style="color: rgb(0, 102, 153); font-weight: bold;">bean</span><span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&gt;</span>&nbsp;&nbsp;&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;"><span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&lt;</span><span class="tag-name" style="color: rgb(0, 102, 153); font-weight: bold;">bean</span>&nbsp;<span class="attribute" style="color: red;">id</span>=<span class="attribute-value" style="color: blue;">"byteArray_hmc"</span>&nbsp;<span class="attribute" style="color: red;">class</span>=<span class="attribute-value" style="color: blue;">"org.springframework.http.converter.ByteArrayHttpMessageConverter"</span>&nbsp;<span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">/&gt;</span><span class="comments" style="color: rgb(0, 130, 0); padding: 0px; margin: 0px; width: auto; border: 0px;">&lt;!--&nbsp;处理..&nbsp;--&gt;</span>&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;"><span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&lt;</span><span class="tag-name" style="color: rgb(0, 102, 153); font-weight: bold;">bean</span>&nbsp;<span class="attribute" style="color: red;">id</span>=<span class="attribute-value" style="color: blue;">"string_hmc"</span>&nbsp;<span class="attribute" style="color: red;">class</span>=<span class="attribute-value" style="color: blue;">"org.springframework.http.converter.StringHttpMessageConverter"</span>&nbsp;<span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">/&gt;</span><span class="comments" style="color: rgb(0, 130, 0); padding: 0px; margin: 0px; width: auto; border: 0px;">&lt;!--&nbsp;处理..&nbsp;--&gt;</span>&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;"><span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&lt;</span><span class="tag-name" style="color: rgb(0, 102, 153); font-weight: bold;">bean</span>&nbsp;<span class="attribute" style="color: red;">id</span>=<span class="attribute-value" style="color: blue;">"resource_hmc"</span>&nbsp;<span class="attribute" style="color: red;">class</span>=<span class="attribute-value" style="color: blue;">"org.springframework.http.converter.ResourceHttpMessageConverter"</span>&nbsp;<span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">/&gt;</span><span class="comments" style="color: rgb(0, 130, 0); padding: 0px; margin: 0px; width: auto; border: 0px;">&lt;!--&nbsp;处理..&nbsp;--&gt;</span>&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;"><span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&lt;</span><span class="tag-name" style="color: rgb(0, 102, 153); font-weight: bold;">bean</span>&nbsp;<span class="attribute" style="color: red;">id</span>=<span class="attribute-value" style="color: blue;">"source_hmc"</span>&nbsp;<span class="attribute" style="color: red;">class</span>=<span class="attribute-value" style="color: blue;">"org.springframework.http.converter.xml.SourceHttpMessageConverter"</span>&nbsp;<span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">/&gt;</span><span class="comments" style="color: rgb(0, 130, 0); padding: 0px; margin: 0px; width: auto; border: 0px;">&lt;!--&nbsp;处理..&nbsp;--&gt;</span>&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;"><span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&lt;</span><span class="tag-name" style="color: rgb(0, 102, 153); font-weight: bold;">bean</span>&nbsp;<span class="attribute" style="color: red;">id</span>=<span class="attribute-value" style="color: blue;">"xmlAwareForm_hmc"</span>&nbsp;<span class="attribute" style="color: red;">class</span>=<span class="attribute-value" style="color: blue;">"org.springframework.http.converter.xml.XmlAwareFormHttpMessageConverter"</span>&nbsp;<span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">/&gt;</span><span class="comments" style="color: rgb(0, 130, 0); padding: 0px; margin: 0px; width: auto; border: 0px;">&lt;!--&nbsp;处理..&nbsp;--&gt;</span>&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;"><span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&lt;</span><span class="tag-name" style="color: rgb(0, 102, 153); font-weight: bold;">bean</span>&nbsp;<span class="attribute" style="color: red;">id</span>=<span class="attribute-value" style="color: blue;">"jaxb2RootElement_hmc"</span>&nbsp;<span class="attribute" style="color: red;">class</span>=<span class="attribute-value" style="color: blue;">"org.springframework.http.converter.xml.Jaxb2RootElementHttpMessageConverter"</span>&nbsp;<span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">/&gt;</span><span class="comments" style="color: rgb(0, 130, 0); padding: 0px; margin: 0px; width: auto; border: 0px;">&lt;!--&nbsp;处理..&nbsp;--&gt;</span>&nbsp;&nbsp;</span></p></li>
     <li><p><span style="color: black;"><span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">&lt;</span><span class="tag-name" style="color: rgb(0, 102, 153); font-weight: bold;">bean</span>&nbsp;<span class="attribute" style="color: red;">id</span>=<span class="attribute-value" style="color: blue;">"jackson_hmc"</span>&nbsp;<span class="attribute" style="color: red;">class</span>=<span class="attribute-value" style="color: blue;">"org.springframework.http.converter.json.MappingJacksonHttpMessageConverter"</span>&nbsp;<span class="tag" style="color: rgb(0, 102, 153); font-weight: bold;">/&gt;</span><span class="comments" style="color: rgb(0, 130, 0); padding: 0px; margin: 0px; width: auto; border: 0px;">&lt;!--&nbsp;处理json--&gt;</span>&nbsp;&nbsp;</span></p></li>
    </ol>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">&nbsp;&nbsp;转载请注明出处：原文地址：<a href="http://elf8848.iteye.com/blog/875830" style="color: rgb(16, 138, 198);">http://elf8848.iteye.com/blog/875830</a></p>
    <p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">&nbsp;</p>
    <p><br></p>
   </div> 
  </div>  
 </body>
</html>